Hi Nicol,
Nicol wrote:
> I would very much like to know how its possible for the computer to
> randomise.
End Quote
Well, actually it isn't very complex, but you will have rto write a
function which does a few things such as seed the randomize function you
are making with the computers time, select a number, and then return it
to the variable calling it. In C#.NET a function to randomly select a
random number would look like this. Make sure say all punctuation is on
and your message window is maximized.
public int RandomNumber(int low, int high)
{
// First we need a temperary random seed object
// to seed our generator.
Random seed = new Random();
// Now, we will advance the seed with the system time
// and store it in the time variable.
int time = seed.Next();
// At this point we will create a random object for
// randomly generating numbers,
// and seed it with the time.
Random select = new Random(time);
// Now, we will select a number from the low and high numbers,
// and then add 1.
int number = select.Next(low, high) + 1;
// Return our random number.
return number;
}
A couple of notes is in .net apps you can also make an call to the
active thread to sleep or wait for so many milliseconds so as to allow
the time on the clock to change. Without changing the time you will
return the same number over and over again. To pause the thread in C#
.net you would use
Thread.Sleep(10;
which would grab the active thread and pause it for 10 ms.
So to use this function it would look like
Thread.Sleep(10);
dice1 = RandomNumber(1, 6);
Thread.Sleep(10);
dice2 = RandomNumber(1, 6);
Which would roll to dice for you and all you need from there is display
or do something based on the dice roll.
_______________________________________________
Gamers mailing list .. [email protected]
To unsubscribe send E-mail to [EMAIL PROTECTED] You can visit
http://audyssey.org/mailman/listinfo/gamers_audyssey.org to make
any subscription changes via the web.