Tech Reviews, Guides, Articles, and Forums for PC Hardware, Modding, and Gaming Enthusiasts
Fury-Tech Forums

Go Back   Fury-Tech Forums > Software Forums > Programming and Coding

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-14-2004, 11:18 AM
Packetrat's Avatar
Greater Overmind
Greater Overmind
 
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
Packetrat is on a distinguished road
Default 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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-14-2004, 11:35 AM
Technophile's Avatar
Super Moderator
Great Diviner
 
Join Date: Sep 2002
Location: Everywhere
Posts: 3,811
Rep Power: 10
Technophile is on a distinguished road
Send a message via AIM to Technophile Send a message via MSN to Technophile Send a message via Yahoo to Technophile
Default

I'm not a PHP expert or anything but don't you need to seed the random number generator to get different values?

http://www.thunderstone.com/site/vortexman/node128.html
http://www.php.net/manual/en/function.srand.php

PHP 4.2 should seed it automatically.
__________________
Your sig is cooler than mine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-14-2004, 12:26 PM
Packetrat's Avatar
Greater Overmind
Greater Overmind
 
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
Packetrat is on a distinguished road
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-14-2004, 01:53 PM
Technophile's Avatar
Super Moderator
Great Diviner
 
Join Date: Sep 2002
Location: Everywhere
Posts: 3,811
Rep Power: 10
Technophile is on a distinguished road
Send a message via AIM to Technophile Send a message via MSN to Technophile Send a message via Yahoo to Technophile
Default

Damn.
__________________
Your sig is cooler than mine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-17-2004, 06:26 PM
Tekime's Avatar
Administrator
Great Diviner
 
Join Date: Aug 2002
Location: Maine
Posts: 5,248
Rep Power: 10
Tekime is on a distinguished road
Send a message via AIM to Tekime Send a message via MSN to Tekime Send a message via Yahoo to Tekime
Default

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.
__________________
ABIT NF8 | Athlon 64 2800+ | 1GB Corsair XMS PC-3200 | MSI GeForce 6600GT

My blog, business, Twitter, ryze, LinkedIn, Digg, Facebook
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-18-2004, 12:03 PM
Packetrat's Avatar
Greater Overmind
Greater Overmind
 
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
Packetrat is on a distinguished road
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-18-2004, 01:57 PM
Tekime's Avatar
Administrator
Great Diviner
 
Join Date: Aug 2002
Location: Maine
Posts: 5,248
Rep Power: 10
Tekime is on a distinguished road
Send a message via AIM to Tekime Send a message via MSN to Tekime Send a message via Yahoo to Tekime
Default

Try typecasting the return field?

Code:
$quote_id = rand(1, (int)$quote_count);
__________________
ABIT NF8 | Athlon 64 2800+ | 1GB Corsair XMS PC-3200 | MSI GeForce 6600GT

My blog, business, Twitter, ryze, LinkedIn, Digg, Facebook
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-20-2004, 02:49 PM
Packetrat's Avatar
Greater Overmind
Greater Overmind
 
Join Date: Feb 2003
Location: Colorado
Posts: 887
Rep Power: 6
Packetrat is on a distinguished road
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Currently Viewing
Go Back   Fury-Tech Forums > Software Forums > Programming and Coding




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 10:57 PM.


PHP Scripts
BidVerve Directory
PageRank Script
SEO Scripts
37 SEO Scripts
List Cleaner Script
Keyword Cleaner
Directory Script
Directory Script

Directories
BidVerve Directory
BidVerve Directory
Nerve Directories
Nerve Directories
Directory Grow
Directory Grow

Our Supporters
entertainment sites
online casino

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.