3.15 Random Values

4 阅读1分钟

1. Exam Points

  • Generate a random value between a specified range.
  • Determine the range of RANDOM(min, max).

2. Knowledge Points

(1) Generate Random Values

  • CSP provides the random procedure to generate and return a random integer from a to b, inclusive (a<= x <=b).
  • Each result is equally likely to occur.
  • For example, RANDOM(1, 3) could return 1, 2, or 3.
  • Syntax:
    image.png
  • Example:
    • x ← RANDOM(1,4)
    • x can be 1, 2, 3, or 4 with a equal chance.

3. Exercises