 |

02-14-2004, 11:18 AM
|
 |
Greater Overmind
Greater Overmind
|
|
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
|
|
PHP rand()
PHP rand(1,132) gives me 101 every time.
__________________
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. - Galileo Galilei
Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. - Thomas Jefferson (3rd US President, author of the Declaration of Independence)
Justice is the [ultimate goal] of government. It is the [ultimate goal] of civil society. It ever has been and ever will be pursued until it be obtained, or until liberty be lost in the pursuit. - James Madison (4th US President, "father" of the US Constitution)
|

02-14-2004, 12:26 PM
|
 |
Greater Overmind
Greater Overmind
|
|
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
|
|
Yeah, I'm using PHP 4.34 and the manual indicates that seeding is not necessary after 4.2 or thereabouts.
__________________
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. - Galileo Galilei
Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. - Thomas Jefferson (3rd US President, author of the Declaration of Independence)
Justice is the [ultimate goal] of government. It is the [ultimate goal] of civil society. It ever has been and ever will be pursued until it be obtained, or until liberty be lost in the pursuit. - James Madison (4th US President, "father" of the US Constitution)
|

02-14-2004, 01:53 PM
|
 |
Super Moderator
Great Diviner
|
|
Join Date: Sep 2002
Location: Everywhere
Posts: 3,811
Rep Power: 10
|
|
Damn.
__________________
Your sig is cooler than mine.
|

02-17-2004, 06:26 PM
|
 |
Administrator
Great Diviner
|
|
Join Date: Aug 2002
Location: Maine
Posts: 5,248
Rep Power: 10
|
|
Have you tried seeding it to see if it still gives you the same number?
And does it give you 101 on every call to the script, or only duplicates when called multiple times from the same script?
If you can post the chunk of code you're using perhaps the context will reveal some more details.
|

02-18-2004, 12:03 PM
|
 |
Greater Overmind
Greater Overmind
|
|
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
|
|
It gives me the same number every time i run the script. rand() is only called once in the entire app, and I've checked the SQL statement that gives me the maximum of 132. It is correct and the value correctly gets passed to the maximum parameter.
Code:
$sql = "SELECT COUNT(*) FROM quote";
$quote_count = mysql_result(mysql_query($sql,$database_link),0);
$quote_id = rand(1,$quote_count);
Echoing quote_id gives me 101 every time.
Part of my problem as a coder in any situation is that I want and expect things to work correctly. If the PHP manual says I don't need to seed the randomizer, I don't. If it tells me I should use $_POST instead of $HTTP_POST_VARS, I do. If the W3C standard says I should no longer use the center tag, I don't. Unfortunately, many of these issues need workarounds in certain instances. &*#$%@!
__________________
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. - Galileo Galilei
Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. - Thomas Jefferson (3rd US President, author of the Declaration of Independence)
Justice is the [ultimate goal] of government. It is the [ultimate goal] of civil society. It ever has been and ever will be pursued until it be obtained, or until liberty be lost in the pursuit. - James Madison (4th US President, "father" of the US Constitution)
|

02-18-2004, 01:57 PM
|
 |
Administrator
Great Diviner
|
|
Join Date: Aug 2002
Location: Maine
Posts: 5,248
Rep Power: 10
|
|
Try typecasting the return field?
Code:
$quote_id = rand(1, (int)$quote_count);
|

02-20-2004, 02:49 PM
|
 |
Greater Overmind
Greater Overmind
|
|
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
|
|
No change.
__________________
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. - Galileo Galilei
Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. - Thomas Jefferson (3rd US President, author of the Declaration of Independence)
Justice is the [ultimate goal] of government. It is the [ultimate goal] of civil society. It ever has been and ever will be pursued until it be obtained, or until liberty be lost in the pursuit. - James Madison (4th US President, "father" of the US Constitution)
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:57 PM.
|
|