PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 1999, 05:40 PM
timboy
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I am using the rand() function in php3. Without arguments it seems to behave as advertised, returning an integer between 0 and getrandmax(). It seems to behave the same way with arguments, though, e.g. rand(1,15) -> 1774965089, rather than a number between 1 and 15.
This is not because I haven't seeded the generator --- I use srand as in the manual before I start making calls to rand.
Also, this would OK if there were a modulus function (e.g. rand() mod 15), but I don't see one in the math section of the manual.
Any help appreciated.

Timboy

Reply With Quote
  #2  
Old June 24th, 1999, 06:03 PM
timboy
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Ooops, modulus is an operator ('%').
rand() still seems to ignore its args, but if anyone else has the same problem, a workaround is something like

function rand_with_args($min, $max)
{
return ($min + rand() % (1 + $max - $min));
}

Timboy


Reply With Quote
  #3  
Old June 25th, 1999, 01:59 PM
timboy
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Replying to myself once again --- the rand() bug was apparently fixed as of PHP version 3.0.7.

Timboy

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > rand() ignores arguments?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap