is random really not so random?


Closed Thread
Results 1 to 8 of 8
  1. #1

    Post is random really not so random?

    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?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    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.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    Quote Originally Posted by HenrikOlsson View Post
    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..

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    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

  5. #5
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    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.

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    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...

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    Not if you are within 20 feet of an AC line.
    Charles Linquist

  8. #8
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: is random really not so random?

    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.
    Charles Linquist

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts