Shop OBEX P1 Docs P2 Docs Learn Events
random number code — Parallax Forums

random number code

sovsov Posts: 17
edited 2010-03-22 08:15 in Propeller 1
hello, I was wondering if there is a code that can have random numbers being generated. I do want whole numbers (in other words absolute numbers) but since I know the absolute # command·I do not need that much of·help there. I thank everyone a lot for helping mesmile.gif

Comments

  • KyeKye Posts: 2,200
    edited 2010-01-26 23:53
    PUB random(seed, maxValue, minValue)
     
      result := ((||(?seed)) // ((||(maxValue - minValue)) + 1))
     
      if(minValue > maxValue)
     
        result += maxValue
     
      else
      
        result += minValue
    


    Enjoy,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • kt88seampkt88seamp Posts: 112
    edited 2010-03-22 04:41
    How do you perform a random number generation between the number's 80000 and 640000 using Chip's truly random number object? There is no seed, just a random long. How do you compute a minimum and a maximum given just that?
  • LeonLeon Posts: 7,620
    edited 2010-03-22 08:15
    This technique should work:

    www.cplusplus.com/reference/clibrary/cstdlib/rand/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
Sign In or Register to comment.