Roll back random generator

rand_back  amount (number)

Roll the random generator back essentially ‘undoing’ the last call to rand. You may specify an amount to roll back allowing you to skip back n calls to rand.

Introduced in v2.7

Examples

# Example 1


  puts rand
  rand_back
           
           
  puts rand
  puts rand



# Basic rand stream rollback
# prints 0.75006103515625
# roll random stream back one
# the result of the next call to rand will be
# exactly the same as the previous call
# prints 0.75006103515625 again!
# prints 0.733917236328125



# Example 2


  puts rand
  puts rand
  puts rand
  puts rand
  rand_back(3)
              
              
              
  puts rand
  puts rand



# Jumping back multiple places in the rand stream
# prints 0.75006103515625
# prints 0.733917236328125
# prints 0.464202880859375
# prints 0.24249267578125
# roll random stream back three places
# the result of the next call to rand will be
# exactly the same as the result 3 calls to
# rand ago.
# prints  0.733917236328125 again!
# prints  0.464202880859375