func_maths_rand.rst 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .. _func_maths_rand:
  2. ====
  3. Rand
  4. ====
  5. Rand -
  6. Description
  7. ===========
  8. .. code-block:: blitzmax
  9. Rand( min_value,max_value=1 )
  10. Generate random integer
  11. The optional parameter allows you to use #Rand in 2 ways:
  12. [ @Format | @Result
  13. * &Rand(x) | Random integer in the range 1 to x (inclusive)
  14. * &Rand(x,y) | Random integer in the range x to y (inclusive)
  15. ]
  16. Parameters
  17. ==========
  18. Return Values
  19. =============
  20. A random integer in the range min (inclusive) to max (inclusive)
  21. Examples
  22. ========
  23. .. code-block:: blitzmax
  24. ' Rand.bmx
  25. ' Toss a pair of dice. Result is in the range 1+1 to 6+6.
  26. ' Count how many times each result appears.
  27. Local count[13]
  28. For n = 1 To 3600
  29. toss = Rand(1,6) + Rand(1,6)
  30. count[toss] :+ 1
  31. Next
  32. For toss = 2 To 12
  33. Print LSet(toss, 5)+count[toss]
  34. Next
  35. See Also
  36. ========