6 random numbers limiting to 49 ?????


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2005
    Posts
    49

    Default 6 random numbers limiting to 49 ?????

    hi i want to generate 6 numbers between 1 - 49 (1 and 49 include) here is my codes but always give me 0 to all numbers and i don't want 6 possibles the same [i think i will use if and then commands really much ]
    i am useing 16f628 in 4 MHz and LCD=16x2
    '''''''''''''''''the codes'''''''''''''''''''''''
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    pause 200
    sayi1 var word
    sayi2 var word
    sayi3 var word
    sayi4 var word
    sayi5 var word
    sayi6 var word
    b1 var byte
    b1=0
    tus_bekle:
    button porta.4 ,0,0,0,b1,1,tus_geldi
    goto tus_bekle
    tus_geldi
    random sayi1
    random sayi2
    random sayi3
    random sayi4
    random sayi5
    random sayi6
    sayi1 =sayi1 & $31
    sayi2 =sayi2 & $31
    sayi3 =sayi3 & $31
    sayi4 =sayi4 & $31
    sayi5 =sayi5 & $31
    sayi6 =sayi6 & $31
    lcdout $fe,1
    lcdout "NUMARALARINIZ"
    LCDOut $Fe,$C0
    LCDOUT #sayi1,":",#sayi2,":",#sayi3,":",#sayi4,":",#sayi5 ,":",#sayi6
    end
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''
    Attached Images Attached Images  
    Asking is not a shame but not learning is a SHAME!!!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi SuB-ZeRo,

    The RANDOM function requires a "Seed" to be placed in the variable before using it.

    For instance,

    sayi1 = 12345
    RANDOM sayi1

    Unfortunately, doing it that way, you will end up with the exact same numbers every time you run the program. One way around it might be to let a Timer free-run untill some external event happens, such as a button press, or maybe a character being received via RS232. Then once that happens, use the timer value as the seed.

    Once you have the seed, you'll need to use the same variable for each of your 6 random numbers, then copy it to the other variables as needed.

    As you start playing with the RANDOM function, you'll realize that it's not very Random at all. If you keep getting random numbers from the same seed, you'll start seeing a repeating pattern. And if the seed is set to 0, you will only get 0's as the random number.

    Keep in mind that the number will be between 1 and 65535 so if you want to limit it to a certain range, you'll have to do a little math on it.

    HTH,
       Darrel

  3. #3
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Unhappy What do u mean?Random is not a random?

    I really dont understand if random is not a random then what does it means?
    Re u try to say :U can not find random numbers with random comman.If i can't find random numbers with random command , how can i find random numbers?Then what the random command do?I really don't understan
    Asking is not a shame but not learning is a SHAME!!!

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Sub-zero,

    SZ>>I really dont understand if random is not a random then what does it means?
    Re u try to say :U can not find random numbers with random comman.If i can't find random numbers with random command , how can i find random numbers?Then what the random command do?I really don't understan <<

    Ok, a computer can *never* really pick a random number... But there are certain "algorithems"<sp> that give a "apparent" random number. Lets take a example ok???

    Lets Look at PI. PI does not have any "repeating" sequences. Thus, we can say the numbers look random. Every time we turn on our computer and say Pick a Random number, it will pick (lets say) the first digit. The next time we call "Random" it will pick the following digit... and so forth... When we turn off our computer and turn it back on, it will start the process all over again... starting with the first digit...second digit... third digit...etc...

    But what happens if you do not want this to happen *exactly* the same, every time you turn on your computer??? You put in a "SEED". A very good seed is the "time".

    digit = time (in seconds) * the Lookup number.

    Thus if time = 5 the first digit is 5 *1 = 5 which means it will look at the 5th digit of PI. The second time it looks it will look at digit #6 etc etc.


    Thus if time = 10 the first digit is 10 *1 = 10 which means it will look at the 10th digit of PI. the second time it looks, it will look at digit #11. etc etc.

    Thus if time = 160 the first digit is 160 *1 = 160 which means it will look at the 160th digit of PI. the second time it looks, it will look at digit #11. etc etc.


    If you notice, the SEED "Time" is *always* varying to *some* degree...Thus when we turn on our computer, the chances that the seed will be the same as before is very slim.


    This is a crude example, but I hope it helps..

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It's called a "Pseudo-Random" number generator.

    It's main use is probably for creating "White Noise" with the SOUND command. Well, truthfully, it creates "Pink Noise", since "White Noise" would require a truly Random number generator.

    I wouldn't want to write a game based on these numbers, because it would become too predictable.

    One possibility for generating better randomness, is to take the amplified noise output from a semiconductor such as diode or transistor (White Noise) and feed that into a timer or A/D Channel. When you use those values, you'll never see a repeating pattern. But then, that means more hardware.

    I see Dwayne beat me to the punch. And, I'll agree. Time would make a good seed, as long as it's a battery backed-up clock that still runs when power is off.

    HTH,
    &nbsp;&nbsp;&nbsp;Darrel
    Last edited by Darrel Taylor; - 15th June 2005 at 20:04.

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


    Did you find this post helpful? Yes | No

    Default

    All of that sounds familiar.. have a look to this thread
    http://www.picbasic.co.uk/forum/show...bartman+random
    Steve

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

Similar Threads

  1. Questions on random numbers and multiplexing LEDs
    By AaronM in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th June 2009, 04:22
  2. Replies: 4
    Last Post: - 15th April 2009, 01:54
  3. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  4. Real Time Clock & Eeprom
    By smart_storm in forum General
    Replies: 8
    Last Post: - 17th February 2006, 19:03
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

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