| 1 |
(* RandomNumber.def provide a set of random number procedures for pervasive types. |
| 2 |
|
| 3 |
Copyright (C) 2012-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
Under Section 7 of GPL version 3, you are granted additional |
| 19 |
permissions described in the GCC Runtime Library Exception, version |
| 20 |
3.1, as published by the Free Software Foundation. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License and |
| 23 |
a copy of the GCC Runtime Library Exception along with this program; |
| 24 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 25 |
<http://www.gnu.org/licenses/>. *) |
| 26 |
|
| 27 |
DEFINITION MODULE RandomNumber ; |
| 28 |
|
| 29 |
(* |
| 30 |
Title : Random |
| 31 |
Author : Gaius Mulley |
| 32 |
System : GNU Modula-2 |
| 33 |
Date : Wed Nov 26 15:38:01 2012 |
| 34 |
Revision : $Version$ |
| 35 |
Description: provides primitives for obtaining random numbers on |
| 36 |
pervasive data types. |
| 37 |
*) |
| 38 |
|
| 39 |
FROM SYSTEM IMPORT BYTE ; |
| 40 |
EXPORT QUALIFIED Randomize, RandomInit, RandomBytes, |
| 41 |
RandomCard, RandomShortCard, RandomLongCard, |
| 42 |
RandomInt, RandomShortInt, RandomLongInt, |
| 43 |
RandomReal, RandomLongReal, RandomShortReal ; |
| 44 |
|
| 45 |
|
| 46 |
(* |
| 47 |
Randomize - initialize the random number generator with a seed |
| 48 |
based on the microseconds. |
| 49 |
*) |
| 50 |
|
| 51 |
PROCEDURE Randomize ; |
| 52 |
|
| 53 |
|
| 54 |
(* |
| 55 |
RandomInit - initialize the random number generator with value, seed. |
| 56 |
*) |
| 57 |
|
| 58 |
PROCEDURE RandomInit (seed: CARDINAL) ; |
| 59 |
|
| 60 |
|
| 61 |
(* |
| 62 |
RandomBytes - fills in an array with random values. |
| 63 |
*) |
| 64 |
|
| 65 |
PROCEDURE RandomBytes (VAR a: ARRAY OF BYTE) ; |
| 66 |
|
| 67 |
|
| 68 |
(* |
| 69 |
RandomInt - return an INTEGER in the range [low .. high]. |
| 70 |
*) |
| 71 |
|
| 72 |
PROCEDURE RandomInt (low, high: INTEGER) : INTEGER ; |
| 73 |
|
| 74 |
|
| 75 |
(* |
| 76 |
RandomShortInt - return an SHORTINT in the range [low..high]. |
| 77 |
*) |
| 78 |
|
| 79 |
PROCEDURE RandomShortInt (low, high: SHORTINT) : SHORTINT ; |
| 80 |
|
| 81 |
|
| 82 |
(* |
| 83 |
RandomLongInt - return an LONGINT in the range [low..high]. |
| 84 |
*) |
| 85 |
|
| 86 |
PROCEDURE RandomLongInt (low, high: LONGINT) : LONGINT ; |
| 87 |
|
| 88 |
|
| 89 |
(* |
| 90 |
RandomShortCard - return a SHORTCARD in the range [low..high]. |
| 91 |
*) |
| 92 |
|
| 93 |
PROCEDURE RandomShortCard (low, high: CARDINAL) : CARDINAL ; |
| 94 |
|
| 95 |
|
| 96 |
(* |
| 97 |
RandomCard - return a CARDINAL in the range [low..high]. |
| 98 |
*) |
| 99 |
|
| 100 |
PROCEDURE RandomCard (low, high: CARDINAL) : CARDINAL ; |
| 101 |
|
| 102 |
|
| 103 |
(* |
| 104 |
RandomLongCard - return an LONGCARD in the range [low..high]. |
| 105 |
*) |
| 106 |
|
| 107 |
PROCEDURE RandomLongCard (low, high: LONGCARD) : LONGCARD ; |
| 108 |
|
| 109 |
|
| 110 |
(* |
| 111 |
RandomReal - return a REAL number in the range 0.0..1.0 |
| 112 |
*) |
| 113 |
|
| 114 |
PROCEDURE RandomReal () : REAL ; |
| 115 |
|
| 116 |
|
| 117 |
(* |
| 118 |
RandomShortReal - return a SHORTREAL number in the range 0.0..1.0 |
| 119 |
*) |
| 120 |
|
| 121 |
PROCEDURE RandomShortReal () : SHORTREAL ; |
| 122 |
|
| 123 |
|
| 124 |
(* |
| 125 |
RandomLongReal - return a LONGREAL number in the range 0.0..1.0 |
| 126 |
*) |
| 127 |
|
| 128 |
PROCEDURE RandomLongReal () : LONGREAL ; |
| 129 |
|
| 130 |
|
| 131 |
END RandomNumber. |