Php generates random numbers that are not repeated

Source: Internet
Author: User
Get a specified number of random numbers from the specified range, which are not repeated. first, put the specified range into an array and retrieve the number from the array, this number is removed from the array every time you extract it. This prevents the number from being Retrieved again next time, so as to achieve non-repetition. get a specified number of random numbers from the specified range, which are not repeated. first, put the specified range into an array and retrieve the number from the array, this number is removed from the array every time you extract it. This prevents the number from being Retrieved again next time, so as to achieve non-repetition.
// Obtain a random number from 100 natural numbers
$ List = 100;
// Take a few
$ Nu = 10;
For ($ s; $ s <$ list; $ s ++ ){
$ A [] = $ s;
}

For ($ I; $ I <$ nu; $ I = $ key ){
For ($ n = rand (0, ($ list-1); $ a [$ n] ==n n; $ a [$ n] = $ list)
{
$ Key ++;
$ Num [] = $ n;
}
}
Print_r ($ num );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.