PIC18F中的随机种子 [英] Random Seed in PIC18F

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

问题描述

我将在PIC18F2550单片机上运行经过修改的DES代码(C语言). 为此,我使用的是mplabx IDE v 2和Mplab xc8 v 1.30.

I'm going to run modified DES code(C language) on the PIC18F2550 microcontroller. For this I am using mplabx IDE v 2 and Mplab xc8 v 1.30.

要修改代码,我需要一个随机数,这样每次运行都会产生不同的数字.

To modify the code, I need a random number so that each run will produce different numbers.

我想使用rand函数,但是我需要一个很好的Srand函数种子!

I want to use the rand function but I need a good seed for Srand function!

好的种子可能是时间,但是由于没有微型或我不知道的东西!

Good seed can be time, but since there is no such thing as a micro or I do not know!!

推荐答案

您可以在EEPROM中存储一个整数值.设备启动时,将其用作种子,然后再次递增并存储它,以便在每次重新引导时您将拥有不同的种子,从而为每次运行产生不同的顺序.这应该足以满足您的需求.

You can store an integer value in EEPROM. When the device boots, you use it as a seed and then increment and store it again so that at every reboot you will have a different seed, producing a different sequence for each run. That should be enough for what you want.

如果您需要一些复杂的东西,可以尝试以下

If you need something a little more sofisticated, you can try this 555+ADC random seed circuit.

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

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