[thelist] srand in php

noah noah at tookish.net
Tue Oct 23 17:44:15 CDT 2001


At 06:01 PM 23/10/2001, Andrew Forsberg wrote:
>>The maximum random number my environment can generate (with mt_ or 
>>standard random number generation) is 2147483647. Perhaps yours is lower, 
>>which would explain why you aren't getting anything with a leftmost digit of 2.
>
>That'd be because that's the maximum int size on my platform:
>
>>The size of an integer is platform-dependent, although a maximum value of 
>>about two billion is the usual value (that's 32 bits signed). PHP does 
>>not support unsigned integers.
>
>Multiplying the five digit number by 100,000 should, according to the 
>docs, force the number to become a float.
>
>You will need to use a float if you really need such a larger number, 
>although that may well cause other problems. Why do you need such a large key?

At 05:58 PM 23/10/2001, Jay Greenspan wrote:
 > Would a 10 character string do the trick? Or does it have
 > to be digits? Do they have to be random or simply unique?
 > Will 9 digits do work?

I'm actually down to only needing 8 now, but there may be a better way to 
do what I'm doing. Basically, I have 9 thumbnails in a 3x3 table, and I'm 
using a random number to choose which ones to display - I parse the random 
number into an array of digits, and for each table cell show the thumbnail 
if the associated digit is even, and don't show it if the digit is odd (the 
reason I only need 8 is that I found it looked a lot better if the centre 
image was displayed, so I decided to always show it). You can see it at 
http://jeaninenoyes.com/biography.php (to the right of the text).

Does anyone know if there's a better way to get 8 random true or false values?

Cheers,
Noah





More information about the thelist mailing list