http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [question] On the topic of randomness.





Laguna Loire wrote:
> 
> Thanks for the response, Tim! :)
> 
> 
> In anycase, with the bag of marbles, I had wondered about how one could
> alter the level of randomness instead of leaving it up to chance, as it
> were. ^_^;;

Let's say you have a bag of red and blue marbles. If there are 10 red
marbles and 90 blue marbles the odds of drawing a red marble is 10% and
a blue is 90%. If you have an array with 100 elements in it, and 10 or
those elements are 0 and 90 are 1 and you use a random integer in the
range of 0 to 99 (assuming 0 based arrays as in C) to select an entry at
random you will find that 10% of the time you get 0 and 90% of the time
you get 1. There is your bag of marbles. Whether you get a 0 (red) or a
1 (blue) is a matter of chance but on average you will see 9 blues for
each red you see.

				Bob P.

> 
> Wing.

Here is a simple fast good random number generator

#ifndef _FRAND_H_
#define _FRAND_H_

//---------------------------------------------------
/*

    An inline replacement for srand() and rand()
    it returns a number between 0 and 0xffff.

    The original code was found in "Graphic Gems II"
*/
//---------------------------------------------------

extern long _FRSEED_;

#define FRAND_MAX (0xffffl)

#define fsrand(seed)    (_FRSEED_ = seed)

#define frand()     ((_FRSEED_ = (((25173l * _FRSEED_) + 13849l))) &
0xffffl)


//---------------------------------------------------

#endif
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html