Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random numbers not starting at 1

Status
Not open for further replies.

KingofSnake

Programmer
Jul 25, 2000
73
US
I'm using the a = int(rnd * number) + 1.&nbsp;&nbsp;Instead of the 1, I use the low number, thinking that that would produce a range.&nbsp;&nbsp;Example: a = int(rnd * 100) + 25 would make a number from 25 to 100.&nbsp;&nbsp;But i don't think it works.&nbsp;&nbsp;How can I do this? <p> <br><a href=mailto:zachberry@hotmail.com>zachberry@hotmail.com</a><br><a href= the Waitress...</a><br>Buy Cheetos and fight world hunger one step at a time.
 
When you say <FONT FACE=monospace>a=int(rnd*100)+1</font>, you're generating a random number from 1 to 100.&nbsp;&nbsp;But when you add 25, you get 25 to 125.&nbsp;&nbsp;So here's the solution:<br><br><FONT FACE=monospace>myrandomnumber=int(rnd*therange)+1+startingnumber</font><br><br>So, for 25 to 100, your range is 75, so<br><br><FONT FACE=monospace>a=int(rnd*75)+26</font><br><br>is what you want.
 
The range 25 to 100 is 100 - 25 + 1.<br>But the difference between <FONT FACE=monospace>a = INT(RND*76)+25</font> and <FONT FACE=monospace>a = INT(RND*75)+26</font> is rather small. After all, we're talking about pseudo-random numbers here.<br>?<br><img src=http:\\vorpalcom.com\images\anibrain.gif><br><br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top