HGE:Tutorials:Random Numbers
allowtransparency="true" frameborder="0" hspace="0" id="I1_1310607737818" marginheight="0" marginwidth="0" name="I1_1310607737818" scrolling="no" src="https://plusone.google.com/u/0/_/+1/button?hl=en-US&jsh=r%3Bgc%2F22326474-d7ea9837#url=http%3A%2F%2Fwww.gpwiki.org%2Findex.php%2FHGE%3ATutorials%3ARandom_Numbers&size=medium&count=true&id=I1_1310607737818&parent=http%3A%2F%2Fwww.gpwiki.org&rpctoken=979516271&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe" tabindex="-1" vspace="0" width="100%" style="position: absolute; left: -10000px; top: -10000px; width: 90px; ">
Random numbers in HGE
HGE includes some random number functions. They are member functions of the HGE class. Access them from the global hge pointer declared at the beginning of the program.
Random_Float(float x, float y): Returns a random float between x and y (inclusive).
Random_Int(int x, int y): Returns a random integer between x and y (inclusive).
Random_Seed(int seed=0): Sets the seed for the random number generator. If the seed is zero or omitted, the current time is used for the seed.
Usually, these statements are used in the following way, assuming hge is the global pointer to the HGE interface:
hge->Random_Seed(0); //sets the seed to the current time int randomNum = hge->Random_Int(30, 50); //generates a random number from 30 to 50
allowtransparency="true" frameborder="0" hspace="0" id="I1_1310607737818" marginheight="0" marginwidth="0" name="I1_1310607737818" scrolling="no" src="https://plusone.google.com/u/0/_/+1/button?hl=en-US&jsh=r%3Bgc%2F22326474-d7ea9837#url=http%3A%2F%2Fwww.gpwiki.org%2Findex.php%2FHGE%3ATutorials%3ARandom_Numbers&size=medium&count=true&id=I1_1310607737818&parent=http%3A%2F%2Fwww.gpwiki.org&rpctoken=979516271&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe" tabindex="-1" vspace="0" width="100%" style="position: absolute; left: -10000px; top: -10000px; width: 90px; ">