# Board index » delphi » random number generator

## random number generator

hey, it's me again
software teacher from hell strikes again...

this time, we need to make a pascal game, that will run with the following
rules:
2 players. player 1 rolls 2 dice, the 2 numbers cannot be equal or
adjascent. If they are, that player looses. If they are not, then player 2
rolls 1 dice. If player 2's number exceeds player 1's numbers, or is equal
to either of player 1's number, player 1 wins. Else, player 2 wins.

ok, here's the problem.
We had to make the program in javascript, and pascal (javascript all done,
no problems there)...
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???

thanx all

- Ollie

## 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

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
______________________________|_______________________________________

## Re:random number generator

JRS:  In article <6Y7M5.8535\$Tq6.79...@news-server.bigpond.net.au> of
Thu, 2 Nov 2000 06:36:50 seen in news:comp.lang.pascal.borland,

##### Quote
SilverFlyingPotato <ollie...@nospam.hotmail.com> wrote:
>How would we go about generating a random number between 1 and 6 on a
>macintosh system running code warrior???