PHP Unique Random Numbers

前端 未结 6 1643
天涯浪人
天涯浪人 2021-01-14 21:16

What would be a good way to generate 7 unique random numbers between 1 and 10. I can\'t have any duplicates. I could write a chunk of PHP to do this (using rand() and pushin

6条回答
  •  囚心锁ツ
    2021-01-14 21:47

    • Create an array from 1 to 10 (range).
    • Put it in random order (shuffle).
    • Select 7 items from the array (array_slice)

提交回复
热议问题