Jump to content

[SOLVED] Generating 6 random digits?


NerdConcepts

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.

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.