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

Symbian 随机数

2013年10月11日 ⁄ 综合 ⁄ 共 514字 ⁄ 字号 评论关闭

无论开发什么程序,尤其是类似纸牌类游戏和拼图类,以及俄罗斯方块之类的游戏,
随机数发生器是必不可少的。标准c语言里面有seed()和rand()用来生成种子和数值
在symbian平台下面,用什么方法呢?下面就是一个例子

TTime theTime( KAknExNoteInitializeTime );
theTime.UniversalTime();
TInt64 randSeed( theTime.Int64() );   // 采用时间初始化随机数种子
TInt number( Math::Rand( randSeed ) % KAknExNoteRandomNumberRange );  // 这里就是调用了
生成的结果放在number中。

 

 

 

获取两个数之间的随机数

 

TInt GetRangNum(TInt startNum,TInt endNum)
{
TTime theTime( startNum );
theTime.UniversalTime();
TInt64 randSeed( theTime.Int64() );
TInt number( startNum + Math::Rand( randSeed ) % (endNum - startNum) );

return number;

}

抱歉!评论已关闭.