View Full Version : is random really not so random?
mrpackethead
- 3rd November 2011, 02:51
I need to do something really simple; I'm using a PIC10F206. All i want to do is delay the startup of another circuit in the range of approximately 0-10 sec. The pin ssr, controlls an external SSR. 65000 / 6 roughly is 11,000 milliseconds close enough for this application.. I will have about 200 of these running in parrallel with each other.. This is my first attempt with Picbasic Pro.. seemed easy enough. Heres the code i wrote.
Start:
low ssr
random startdelay
startdelay = startdelay / 6
pause startdelay
high ssr
goto forever
forever:
goto forever
It seemed to work.. It delayed the start up.. However.. i released that the startup was the same *every* time i started it.. and when i put a second one together, it was also delayed by the identical time.. It seems to me that the randomness is not so random, and it might be following some kind of pseudo random pattern.. How could i actually get a varying random?
HenrikOlsson
- 3rd November 2011, 06:25
Hi,
No, it's not really random. From the manual
Random VAR
Perform one iteration of pseudo-randomization on Var.
What you can do (don't know if it's enough though) is to seed to "randomizer". You do this by presetting VAR (stardelay in your case) with a number which will be used as the seed. If you initialise startdelay variable to a different value on each device they won't act the same. Each individual device will, however, act the same every time it starts up - just not equal to the one next to it.
Like I said, don't know if that's "random" enough for you.
/Henrik.
mrpackethead
- 3rd November 2011, 10:16
Hi,
No, it's not really random. From the manual
What you can do (don't know if it's enough though) is to seed to "randomizer". You do this by presetting VAR (stardelay in your case) with a number which will be used as the seed. If you initialise startdelay variable to a different value on each device they won't act the same. Each individual device will, however, act the same every time it starts up - just not equal to the one next to it.
Like I said, don't know if that's "random" enough for you.
/Henrik.
While that woudl work, it would be just as simple to set a pause of different lengths on different devices. For the sake of programming hundreds of these things, it would be good if i could use the same program or i'll be compiling a lot of different variants.. I'm just trying to think what i coudl use to provide some 'randomness' to the seeding..
amgen
- 3rd November 2011, 10:28
if you could daisy-chain them with 1 wire to each, each one could wait until signaled that the downline started, wait x-milliseconds to start, then signal to the next up-line device..... etc.
Don
dhouston
- 3rd November 2011, 11:14
I've never tried it on a PIC but on another MCU as well as on a PC I have used the modulus operator with a timer count to randomize a time-of-day event. With a PIC there might be enough variation in the different oscillators to give you a pseudo-random value with a 16-bit counter but probably not with an 8-bit counter. Perhaps you could do something along these lines with the watchdog timer.
pedja089
- 3rd November 2011, 11:23
Use 1 pin for count, and put piece of wire on it to act as antenna, you should able to pickup noise from environment. I think that is real random...
Charles Linquis
- 4th November 2011, 01:52
Not if you are within 20 feet of an AC line.
Charles Linquis
- 4th November 2011, 01:57
How about using a Dallas 1-wire device? Each one has a globally unique serial number. Take the last 8 digits and reverse them, so that the LSB becomes the MSB. That way, if you get two that have sequential serial numbers, the result will still be significantly different.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.