princeofpersia Posted November 26, 2010 Share Posted November 26, 2010 Hi Guys I have a code what inserts very simple queries to database, im trying to add a random reference number for each enrty using $reference = rand(111111111111,999999999999); but each time I add an entry it gives me the same random number previously generated for previous entry can you help pleasE? Link to comment https://forums.phpfreaks.com/topic/219905-random-number/ Share on other sites More sharing options...
MrXHellboy Posted November 26, 2010 Share Posted November 26, 2010 Try: mt_srand((double)microtime()*1000000); $reference = mt_rand(111111111111,999999999999); Link to comment https://forums.phpfreaks.com/topic/219905-random-number/#findComment-1139941 Share on other sites More sharing options...
waterssaz Posted November 26, 2010 Share Posted November 26, 2010 If you say you are putting multiple entries into the database, I presume you are using some kind of loop, if so is $reference set inside or out of the loop? :-) Link to comment https://forums.phpfreaks.com/topic/219905-random-number/#findComment-1139942 Share on other sites More sharing options...
princeofpersia Posted November 26, 2010 Author Share Posted November 26, 2010 yeah, i have solved it, I have changed the number from $reference = rand(111111111111,999999999999); to $reference = rand(11111111,99999999); so less digits and it work fine, im not using loop but I have tried it few times and now it gives me different reference numbers each I add an entry, thanks for you time guys Link to comment https://forums.phpfreaks.com/topic/219905-random-number/#findComment-1139946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.