HGE:Tutorials:Random Numbers

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; ">


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值