1

I writing an application in AVR Studio 4 which generates random numbers and outputs them on a seven segment display. At the moment i am using a seed, the seed value then gets randomized and the value output. This method obviously produces the same random number sequence (and displays the same sequence) every time the program is run. Is there an alternate method i can use which does not use a seed and as such does not start the program with the same number each time, allowing for different random numbers.

Thanks

4

1 回答 1

3

每次微控制器启动时,它所看到的内部状态都与其他启动时完全相同。这意味着无论您使用何种算法,它的输出都将始终相同。

让它产生不同行为的唯一方法是通过引入一些外部信息或通过在启动之间存储状态来以某种方式在启动时修改其状态。关于如何执行第一个选项的一些想法可能是测量用户按键的持续时间(如果您的系统有按钮)或感测温度或其他外部输入并使用它来播种算法。然而,最简单的选择可能是在 EEPROM 中存储一个计数器,该计数器在每次启动后递增,并使用它来生成种子。

于 2015-03-23T01:13:43.840 回答