取一组数字,然后在php中从该数组中随机取出25个数字
问题描述:
Ok, so I am a bit lost here..
I am pulling profile IDs from an sql database into an array.
i would like to then take that array and randomly pick only 25 numbers each time the array loads, then shuffle up the numbers so there is less likely a chance they will show up in the same order.
好的,我在这里有点迷失.. p>
我是 将配置文件ID从一个sql数据库中拉入一个数组。 p>
我想接着那个数组,每次加载数组时只随机选择25个数字,然后将数字随机抽取,这样就可以了 他们不太可能以同样的顺序出现。 p> div>
答
You can do this in MySQL directly:
SELECT id FROM profiles ORDER BY RAND() LIMIT 25
RAND()
sorts randomly. This should be guarantee enough that "there is less likely a chance they will show up in the same order". If you have more stringent demands on randomness, like uniqueness over draws you might need a more complex solution.
答
shuffle($numbers);
then
array_pop ($numbers)