logo elektroda
logo elektroda
X
logo elektroda

[OpenBeken] Examples of Using Random Number Generation in AUTOEXEC.BAT Files

jkwim 219 4
ADVERTISEMENT
  • #1 21629387
    jkwim
    Level 13  
    With reference to the discussion:
    https://www.elektroda.com/rtvforum/topic4040228.html

    Can you show me few examples as to how the random number generation function can be used in autoexec.bat please?

    Thanks in advance!
  • ADVERTISEMENT
  • #2 21629992
    Drakarah
    Level 5  
    
    alias doSomething echo "Do something"
    if $rand01<0.1 then doSomething
    


    This will do something 10% of the time, you can adjust 0.1 to have a different percentage

    You can schedule that with addRepeatingEvent 1 -1 that will evaluate that every second, so it will do something on average 1 in every 10 seconds sometimes more, sometimes less. doSomething can be whatever you want it to be.
  • ADVERTISEMENT
  • #3 21630009
    jkwim
    Level 13  
    >>21629992
    Thanks. I think I now have an idea about the basic syntax.

    What about the RAND_MAX?
    Can I do something like rand0100 to have more granularity?
  • ADVERTISEMENT
  • #4 21630793
    Drakarah
    Level 5  
    As far as I know $RAND_MAX doesn't exist as a constant, but you can have all the granularity you want with $rand01 because you can do arithmetic operations on it

    For example:
    
    $rand01*100
    


    Will give you a random number between 0 and 99.

    If you use it in an if expression make sure to not use spaces in the expression.

    There's also $rand but that only seems to return even numbers, I'm not sure what is up with that.
  • #5 21631238
    jkwim
    Level 13  
    >>21630793
    Got it.
    Thanks!
ADVERTISEMENT