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

问题描述

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

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

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

有更好的方式)。

解决方案




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


DES

-

Dag-Erling Sm?rgrav -




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

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

根本没有实现太多。


-

Randy Howard(2reply)删除FOOBAR)

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





播种一次。期。如果单独调用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).

解决方案



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

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




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




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


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

08-15 18:16