Jump to content

Recommended Posts

I am trying to generate a random 6 digital number. All I know how to do is " rand(1,10); " and stuff like that, but that won't work. The number I am trying to generate needs to use 0-9 and come up with 6 digits every time. I'm sure this is something I should already know, but the whole MD5 stuff is WAY to large of a number for an in-house RA number :)

 

Only idea I have is to run the "rand(0,9)" (if that is possible, haven't tried it) 6 different times with variable names and then put them together, but there has to be a better way, right?

Link to comment
https://forums.phpfreaks.com/topic/61132-solved-generating-6-random-digits/
Share on other sites

I know the sign says solved, but here's the one I just used yesterday and it seems to play nicely.

 

<?php echo rand(0, 999999); ?>

 

No, it does not meet the parameters that the poster asked for. Namely, if the value of rand is less than 100,000 the value should be padded with zeros to make the value exactly 6 digits. You may not have found that problem with your code because you will only get a value that requires padding about 10% of the time. Try running it several times and you will see the problem.

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.