How random is "RANDOM"?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263

    Default How random is "RANDOM"?

    I'd like to get a better feeling for how random the result from RANDOM is. Any comments?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    IIRC, it repeats every 65,000 times.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tenaja View Post
    IIRC, it repeats every 65,000 times.
    IF you use the same seed value every time, yes, it repeats the same sequence every 65535 time.
    However, whenever I'm using RANDOM, I use a whatever 16-bit I have free as the seed value. That works as long as I'm not grabbing the 16-bit timer value at the same exact time every time.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/showthread.php?t=7555&

    If you want something really random... white noise generator fed to an internal PIC counter + using a random sampling time... even the white noise generator with Count would probably do.

    Tons of way to Fry and egg
    Tons of way to Skin a Cat
    Every road leads to Roma

    Choose the one who fits your local expression
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I guess my question was a little broad. Let me refine it.

    For example, were I to generate random intervals between 1 and 10 seconds long (inclusive) doing this:

    Code:
                 SEED=32771
    LOOP:  	RANDOM SEED
    	TIME=(SEED//10)+1
    	TIME=1000*TIME
       	HIGH LED        	
           	PAUSE TIME		
                 LOW LED         	
           	PAUSE 1000		
                 GOTO LOOP		
                 END
    . . . can I expect the distributions to "look" really random? (In 100 loops, can I expect to see about 10 of each value in each category of 1 second, 2 seconds . . . 10 seconds, etc.?) And, in the sequence, will I see a discernable pattern?

    In some small BASIC implementations, I've had to do the equivalent of this:

    Code:
                 SEED=32771
    LOOP:  	RANDOM SEED
    	TIME=(SEED//11)+1
    	IF TIME<2 OR TIME>10 THEN GOTO LOOP
    	TIME=1000*TIME
       	HIGH LED        	
           	PAUSE TIME		
                 LOW LED         	
           	PAUSE 1000		
                 GOTO LOOP		
                 END
    . . . in order to get good distributions of small numbers.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Probably you'll have better results if you change the SEED value.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  2. 6 random numbers limiting to 49 ?????
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2005, 23:27
  3. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  4. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Members who have read this thread : 1

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