/tutorial/random/example1.e

http://github.com/tybor/Liberty · Specman e · 43 lines · 37 code · 5 blank · 1 comment · 1 complexity · 4bfa077d1208ae8760cc36742b3f34c0 MD5 · raw file

  1. class EXAMPLE1
  2. create {ANY}
  3. main
  4. feature {}
  5. main
  6. local
  7. count, range, column: INTEGER
  8. do
  9. io.put_string("Using the MINIMAL_RANDOM_NUMBER_GENERATOR random number generator.%NHow many numbers? ")
  10. io.read_integer
  11. count := io.last_integer
  12. io.put_string("Range ( > 1) ? ")
  13. io.read_integer
  14. range := io.last_integer
  15. from
  16. until
  17. count = 0
  18. loop
  19. random_number_generator.next
  20. io.put_integer(random_number_generator.last_integer(range))
  21. count := count - 1
  22. if column = 6 then
  23. io.put_string("%N")
  24. column := 0
  25. else
  26. column := column + 1
  27. io.put_string("%T")
  28. end
  29. end
  30. io.put_string("%N")
  31. end
  32. feature {}
  33. random_number_generator: RANDOM_NUMBER_GENERATOR
  34. -- Note: this is a once function in order to use always the same RANDOM_NUMBER_GENERATOR.
  35. once
  36. create {MINIMAL_RANDOM_NUMBER_GENERATOR} Result.make
  37. end
  38. end -- class EXAMPLE1