Jump to content

help for newby!


bobrandolf1

Recommended Posts

Hi guys,

 

I have searched the forum but can't find the answer... I am sure its very simple.

 

All I want is to generate a new Unique ID on each line, I need 200. I can then copy and paste them.

 

So far I have,

 

<?

$uniqueid = md5(uniqid(rand(), true));

echo "$uniqueid<br>";

?>

 

How would I get this script to repeat itself on a new line, do you have to make PHP count?

 

Thanks in advance!

 

Bob in London

Link to comment
https://forums.phpfreaks.com/topic/131484-help-for-newby/
Share on other sites

if this is for a database table, there are other and better ways to do this.

if this is for html output, and you want 200 just loop the code you have 200 times:

for($i = 0; $i < 200; ++$i){
         $uniqueid = md5(uniqid(rand(), true)); //i would change uniqid(rand(), true)) to time(), since that will give you a unique md5 as well, but will call less functions.
         echo "$uniqueid<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682834
Share on other sites

for ($i = 0; $i <= 200; $i++) {
    echo rand(10000, 99999) . '<br />';
}

 

Would print 200 unique 5 digit numbers..

 

No it wouldn't. It would print 201 random 5 digit numbers. Who's to say the same number doesn't appear twice? If you were to do it that way, you'd have to add the numbers to an array then check the array to see if the new generated number isn't already present.

 

:P

Link to comment
https://forums.phpfreaks.com/topic/131484-help-for-newby/#findComment-682841
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.