## Re:random number generator

##### Quote

SilverFlyingPotato <ollie...@nospam.hotmail.com> wrote:

> we need an algorithm that will generate a random number between 1 and 6...

> the problem:

> the schools macintoshes run metrowerks code warrior, which doesn't support

> the borland function for generating random numbers. Thus, we need to use a

> seed. The problem: we get all sorts of numbers, which we can't get between 1

> and 6. How would we go about generating a random number between 1 and 6 on a

> macintosh system running code warrior???

First, a reminder that this newsgroup is intended for discussion of

programming with Borland's Pascal tools; your question probably belongs on

comp.lang.pascal.misc instead.

Anyway, for something like this you should probably just use something like

dicenum := myrandomnumber mod 6 + 1;

assuming that "myrandomnumber" is guaranteed non-negative; if this is not

the case use abs(myrandomnumber) instead of myrandomnumber.

This is not the cleanest method for generating random numbers in a

particular range, but it'll do for this application.

--

______________________________________________________________________

The Scarlet Manuka, | Nitpickers' Party motto:

Pratchett Quoter At Large, | "He who guards his lips guards his

First Prophet of Bonni, is: | soul, but he who speaks rashly will

sa...@maths.uwa.edu.au | come to ruin." -- Proverbs 13:3

______________________________|_______________________________________