hmdnawaz Posted February 3, 2011 Share Posted February 3, 2011 How to generate a unique random number in php??? Any one who can helpĀ me? Quote Link to comment https://forums.phpfreaks.com/topic/226542-how-to-generate-a-unique-random-number-in-php/ Share on other sites More sharing options...
gristoi Posted February 3, 2011 Share Posted February 3, 2011 You need to use the rand() function. Rand($minrange, $maxrange); // so for example Rand (0,10); // will generate a random number between 0 and 10 Quote Link to comment https://forums.phpfreaks.com/topic/226542-how-to-generate-a-unique-random-number-in-php/#findComment-1169277 Share on other sites More sharing options...
hmdnawaz Posted February 3, 2011 Author Share Posted February 3, 2011 It will generate a random number but i want a UNIQUE random number to be generated. Quote Link to comment https://forums.phpfreaks.com/topic/226542-how-to-generate-a-unique-random-number-in-php/#findComment-1169279 Share on other sites More sharing options...
Mr_J Posted February 3, 2011 Share Posted February 3, 2011 The rand function will generate unique no's. You can use mt_rand as well. To make sure you always start from a different place in sequence, you have to seed the random number generator by calling the srand function - mt_srand Quote Link to comment https://forums.phpfreaks.com/topic/226542-how-to-generate-a-unique-random-number-in-php/#findComment-1169281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.