如何在XNA游戏中使用差数进行随机化? [英] How to random with differrence number in XNA game?
本文介绍了如何在XNA游戏中使用差数进行随机化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在开发自己的游戏,而Random()
却有问题.
当游戏运行时,Random()
只会给我一个相同的数字.
Hi everyone,
I am developing my own game and I have a problem with Random()
.
When game runs, the Random()
merely gives me a same number.
if (seconds % 5 == 0 && seconds != 0 && animal_appearance == false)
{
animal_appearance = true;
Last_animal += seconds;
anime_Index =new Random().Next(9);
}
我的第一次跑步:Random()
给我6,然后在10秒后再次给我6.
在我的第二轮比赛中,第一轮是1,而不是6
我真的不知道.
真诚的.
My first run: Random()
give me 6 and then after 10 seconds it again gives me 6.
On my second run as first run but 1 instead of 6
I am really have no idea of this.
Sincerely.
推荐答案
您在犯随机数时常犯错误.
请参阅随机 [
You are making a common mistake for random numbers.
See the MSDN Documentation on Random[^] Seeding.
Random numbers are actually pseudo random and the clock is used by default for its seed (you can provide your own though).
To solve, you can make a single random object and have your own seed value (int) rather than the default.
Random _randSeed = new Random(GetSavedSeedValue());//Get a seed value from somewhere
...
if (seconds % 5 == 0 && seconds != 0 && animal_appearance == false)
{
animal_appearance = true;
Last_animal += seconds;
anime_Index = _randSeed.Next(9);
}
thx ^^.
先生迟到了.
我最近很忙.谢谢你的回答.
我会尽力的.
多谢.
真诚的.
thx^^.
Sr for being late.
I have been busy recently. Thx for ur answer.
I will try my best.
Thx alot.
Sincerely.
这篇关于如何在XNA游戏中使用差数进行随机化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文