1 (* RandomNumber.def provide a set of random number procedures for pervasive types.
3 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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.
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/>. *)
27 DEFINITION MODULE RandomNumber ;
33 Date : Wed Nov 26 15:38:01 2012
35 Description: provides primitives for obtaining random numbers on
39 FROM SYSTEM IMPORT BYTE ;
40 EXPORT QUALIFIED Randomize, RandomInit, RandomBytes,
41 RandomCard, RandomShortCard, RandomLongCard,
42 RandomInt, RandomShortInt, RandomLongInt,
43 RandomReal, RandomLongReal, RandomShortReal ;
47 Randomize - initialize the random number generator with a seed
48 based on the microseconds.
55 RandomInit - initialize the random number generator with value, seed.
58 PROCEDURE RandomInit (seed: CARDINAL) ;
62 RandomBytes - fills in an array with random values.
65 PROCEDURE RandomBytes (VAR a: ARRAY OF BYTE) ;
69 RandomInt - return an INTEGER in the range [low .. high].
72 PROCEDURE RandomInt (low, high: INTEGER) : INTEGER ;
76 RandomShortInt - return an SHORTINT in the range [low..high].
79 PROCEDURE RandomShortInt (low, high: SHORTINT) : SHORTINT ;
83 RandomLongInt - return an LONGINT in the range [low..high].
86 PROCEDURE RandomLongInt (low, high: LONGINT) : LONGINT ;
90 RandomShortCard - return a SHORTCARD in the range [low..high].
93 PROCEDURE RandomShortCard (low, high: CARDINAL) : CARDINAL ;
97 RandomCard - return a CARDINAL in the range [low..high].
100 PROCEDURE RandomCard (low, high: CARDINAL) : CARDINAL ;
104 RandomLongCard - return an LONGCARD in the range [low..high].
107 PROCEDURE RandomLongCard (low, high: LONGCARD) : LONGCARD ;
111 RandomReal - return a REAL number in the range 0.0..1.0
114 PROCEDURE RandomReal () : REAL ;
118 RandomShortReal - return a SHORTREAL number in the range 0.0..1.0
121 PROCEDURE RandomShortReal () : SHORTREAL ;
125 RandomLongReal - return a LONGREAL number in the range 0.0..1.0
128 PROCEDURE RandomLongReal () : LONGREAL ;