Re: Problem with rand()
- From: Anthony Papillion <papillion@xxxxxxxxx>
- Date: Mon, 1 Dec 2008 12:19:45 -0800 (PST)
On Dec 1, 1:50 pm, "Len Bell" <lsb...@xxxxxxxxxxx> wrote:
"Mike" <ampel...@xxxxxxxxx> wrote in message
news:ccc46c96-5185-4871-b7bc-c3aa2f3933c9@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I am using the rand function to create a UID and have noticed a
problem.
Here is my code:
$s_key = mt_rand(1111111,2147411);
I then insert the number into a Mysql as a Varchar(10) , but every
once in a while i get a value in the db like this:
466582143
What could be going wrong?
Thanks
Mike
Could your platform not allow such large integers?
I just looked at my docshttp://www.php.net/manual/en/language.types.integer.php
and found
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. Integer size can be determined using the constant
PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP
4.4.0 and PHP 5.0.5.
Len
It could be that it's too large of a number but I don't use mt_rand()
very often so I couldn't say for sure. Why not do this: manually
input the correct number into the db field and save it. Then, look if
it generates errors or changes the number in any way. If you suspect
the problem is on PHP's side, create a variable with the correct
number then try echoing it to see what happens.
Anthony
.
- References:
- Problem with rand()
- From: Mike
- Re: Problem with rand()
- From: Len Bell
- Problem with rand()
- Prev by Date: Re: URL parameters
- Next by Date: Re: URL parameters
- Previous by thread: Re: Problem with rand()
- Next by thread: question about corrupt db?
- Index(es):
Relevant Pages
|