真的随意吗? [英] Truly random?

查看:83
本文介绍了真的随意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我正在用SDL开发一个俄罗斯方块游戏,但当谈到确定下一个区块的
时,我被卡住了。这是随机的,但是当我尝试使用时间器播种随机发生器时,它就像一个块可以下降一样快速更新为

,接下来要确定。在一个支线中生成

不同的数字可以起作用,但是人们可以玩俄罗斯方块来获得
小时(甚至几天),所以你无法预测多长时间。你可以继续使用与制作相同的系统制作更多的东西,比如种子中的5个随机的b $ b数字,但如果
那将证明系统密集。
游戏已经使用了大量的内存(不是那个俄罗斯方块,但我很确定

有更好的方式)。

解决方案

" Alvin" <人*********** @ gmail.com>写道:

嗯,我正在用SDL开发一个俄罗斯方块游戏,但是当决定下一个块时,我被卡住了。它是随机的,但是当我尝试像随机时间播种随机器时,它不会快速更新,因为一个块可以下降,而下一个块可以确定。




你只需要在游戏开始时播种PRNG一次。


DES

-

Dag-Erling Sm?rgrav - de *@des.no


Alvin写了

(文章

< 11 ****************** ****@f14g2000cwb.googlegroups .com>):

嗯,我正在开发SDL的俄罗斯方块游戏,但是当谈到决定下一个块,我被困住了。它是随机的,但是当我尝试像随机时间播种随机器时,它不会快速更新,因为一个块可以下降,而下一个块可以确定。




听起来你正试图在每次随机通话中播种。你只需要播种一次,或者每场比赛最坏的情况一次,

不是每次都是。这会让事情变得相当缓慢,并且

根本没有实现太多。


-

Randy Howard(2reply)删除FOOBAR)

精确观察的力量被那些没有得到它的人称为玩世不恭。 - George Bernard Shaw


如果你想要真正随机的数字,

忘记像兰特这样的PRNG ()或随机()。 PR部分代表

PSEUDO-RANDOM。计算机并不擅长生成真正的随机数字,除非它们坏了或者它们有特定的硬件

。一些尝试真正随机数生成

时间击键,或听取热噪声或放射性衰变,或b $ b b或来自计算机外部的时间事件(如网络流量)。 />

如果您需要真正的随机数字进行加密,那么PRNG就不会这么做了。区别可能会让你死亡。

好吧,我正在用SDL开发一个俄罗斯方块游戏,但是当谈到决定下一个区块的时候,我是卡住。它是随机的,但是当我尝试像随机时间器播种随机器时,它不会快速更新,因为一个块可能会下降,而下一个块将被确定。生成


不要多次播种PSEUDO随机数生成器。由于

time()调用在大多数(POSIX)
系统上给出了几秒钟的时间粒度,并且可能阻止更新比这更快,你会得到

sucky非随机数。

一个支线中的不同数字可以工作,但人们可以玩几个小时(甚至几天)的俄罗斯方块,所以你可以'预测多久。你可以继续使用与制作相同的系统制作更多,比如种子中的5个随机数字,但如果
游戏已经使用了大量内存,这将证明系统密集(不是俄罗斯方块,但我确定
有更好的方法。)




播种一次。期。如果单独调用rand()或random()减慢显示太多,可能需要更快的CPU。但我对此表示怀疑。

所有图形可能需要更多的工作而不仅仅是生成

a伪随机数。


Gordon L. Burditt


Well, I''m developing a Tetris game in SDL, but when it comes to
deciding the next block, I''m stuck. It''s random, but when I try
something like seeding the randomizer with the time, it won''t update as
fast as one block can fall, and the next to be determined. Generating
different numbers in one spur can work, but people can play Tetris for
hours (or even days), and so you can''t predict how long. You could
constantly be making more with the same system as making, say 5 random
numbers out of a seed, but that would prove system intensive if the
game already uses a lot of memory (not that Tetris does, but I''m sure
there''s a better way).

解决方案

"Alvin" <al***********@gmail.com> writes:

Well, I''m developing a Tetris game in SDL, but when it comes to
deciding the next block, I''m stuck. It''s random, but when I try
something like seeding the randomizer with the time, it won''t update as
fast as one block can fall, and the next to be determined.



You only need to seed the PRNG once, at the start of the game.

DES
--
Dag-Erling Sm?rgrav - de*@des.no


Alvin wrote
(in article
<11**********************@f14g2000cwb.googlegroups .com>):

Well, I''m developing a Tetris game in SDL, but when it comes to
deciding the next block, I''m stuck. It''s random, but when I try
something like seeding the randomizer with the time, it won''t update as
fast as one block can fall, and the next to be determined.



It sounds like you are trying to seed on every random call. You
only need to seed it once, or perhaps once per game worst case,
not every time. That would slow things down quite a bit, and
not achieve much at all.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw


If, as your subject line suggests, you want truly random numbers,
forget a PRNG like rand() or random(). The PR part stands for
PSEUDO-RANDOM. Computers aren''t very good at generating truly
random numbers unless they are broken or they have specific hardware
for the purpose. Some attempts at truly random number generation
time keystrokes, or listen to thermal noise or radioactive decay,
or time events from outside the computer (like network traffic).

If you need truly random numbers for cryptography, a PRNG won''t
do. The difference can get you killed.

Well, I''m developing a Tetris game in SDL, but when it comes to
deciding the next block, I''m stuck. It''s random, but when I try
something like seeding the randomizer with the time, it won''t update as
fast as one block can fall, and the next to be determined. Generating
Don''t seed the PSEUDO random number generator more than once. Since
the time() call gives a time granularity of seconds on most (POSIX)
systems, and presumably blocks update faster than that, you''ll get
sucky non-random numbers.
different numbers in one spur can work, but people can play Tetris for
hours (or even days), and so you can''t predict how long. You could
constantly be making more with the same system as making, say 5 random
numbers out of a seed, but that would prove system intensive if the
game already uses a lot of memory (not that Tetris does, but I''m sure
there''s a better way).



Seed once. Period. If calling rand() or random() alone slows down
the display too much, perhaps you need a faster CPU. But I doubt it.
All the graphics probably takes a lot more work than just generating
a pseudo-random number.

Gordon L. Burditt


这篇关于真的随意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆