Generate a random number between 0 and X


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I know i could get to the correct value using the following equation
    Rnd1 = (Rnd0.byte0 / 255) * lim

    That one wont work though because it will be rounded to 0 or 1 when dividing.
    Tray to multiply first.

    Rnd1 = (Rnd0.byte0 * lim)/ 255 [which is the same as Rnd1 = (Rnd0 */ lim)]

    Al.
    All progress began with an idea

  2. #2
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ahh, I think i understand how */ is working now. Ive tried both ways and they seem to be working for a few seconds then my LED freezes but i think thats to do with something else. Thanks for your help

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ive figured why the LED freezes now. After generating the random number i was using */ and storing the result back in the same variable. It looks like the RANDOM command uses whats already in the variable as a seed and as i was modifying the value to really low numbers, eventually it was hitting 0 and staying there. I added a second variable and its all working now

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