现在的位置: 首页 > 综合 > 正文

HGE:Tutorials:Random Numbers

2014年09月05日 ⁄ 综合 ⁄ 共 660字 ⁄ 字号 评论关闭


HGE:Tutorials:Random Numbers 

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

抱歉!评论已关闭.