PHP Unique Random Numbers

前端 未结 6 1709
天涯浪人
天涯浪人 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:43

    Whole numbers? Well, if you want 7 out of 10 then you more efficiently DON'T want 3 out of 10.

    Feel free to use any of the other responses but instead of creating 7 numbers start with 10 and eliminate 3. That will tend to speed things up by more than double.

提交回复
热议问题