newbie REALbasic question (random numbers)
Author Message
newbie REALbasic question (random numbers)

rnd*(max-min)+min

--------------------------------------------------------
| Adam Robinson         | www.realbasic.com              |
| REALsoftware Support  | www.free-host.com/realweb      |

|--------------------------------------------------------|
|                    Try REALbasic!                      |
|           True RAD for the Mac and Windows!            |
--------------------------------------------------------

Quote:

> Organization: http://www.*-*-*.com/
> Newsgroups: comp.lang.basic.realbasic
> Date: Wed, 03 Nov 1999 00:23:47 -0700
> Subject: newbie REALbasic question (random numbers)

> I've been playing around with the Real Basic demo for a few days.
> Sometimes I get extremely frustrated, but I (barely) understand enough so
> my experimenting has been more fun than not.

> A quick question:

> How do I generate random numbers and then pass that number on to a text
> field? I tried rnd, but it only returns a value of either 0 or 1.

> How can I generate random numbers based on a range I specify? Say I want
> to generate a random number from 1 to 6, or 5 to 13 (or any arbitrary
> range for that matter)?

Sun, 21 Apr 2002 03:00:00 GMT
newbie REALbasic question (random numbers)

Most random number generators will give you a random number between 0 and
1, then you can scale that number to the range you want by multiplying it
by the range.

Example, let's say you want a random integer between 5 and 13 (min 5, max
13, range 8):

dim r as integer
r = 5 + ( rnd * 8 )

Hope this helps,

Quote:

> Hi all,

> I've been playing around with the Real Basic demo for a few days.
> Sometimes I get extremely frustrated, but I (barely) understand enough so
> my experimenting has been more fun than not.

> A quick question:

> How do I generate random numbers and then pass that number on to a text
> field? I tried rnd, but it only returns a value of either 0 or 1.

> How can I generate random numbers based on a range I specify? Say I want
> to generate a random number from 1 to 6, or 5 to 13 (or any arbitrary
> range for that matter)?

____Nicholas C. DeMello, Ph.D., Editor_________________________________
MacTech Magazine, the Journal of Macintosh Technology & Development
http://www.MacTech.com/
_/   _/  _/  _/_/_/   _/   _/
_/_/ _/  _/  _/   _/  _/_/_/

http://www.nick.demello.com/    _/   _/  _/   _/_/_/  _/   _/

Sun, 21 Apr 2002 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages