Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.