| 1 |
(* Copyright (C) 2005-2025 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of Chisel. |
| 3 |
|
| 4 |
Chisel is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 3, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
Chisel is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) |
| 17 |
|
| 18 |
DEFINITION MODULE Chance ; |
| 19 |
|
| 20 |
(* |
| 21 |
Title : Chance |
| 22 |
Author : Gaius Mulley |
| 23 |
Date : 19/7/88 |
| 24 |
LastEdit : 19/7/88 |
| 25 |
System : LOGITECH MODULA-2/86 |
| 26 |
Description: Provides a set of utilities for random numbers. |
| 27 |
*) |
| 28 |
|
| 29 |
EXPORT QUALIFIED InitRandom, KillRandom, |
| 30 |
GetAndDeleteRandom, AddRandom, GetRand, GetSeed, SetSeed ; |
| 31 |
|
| 32 |
(* |
| 33 |
InitRandom - Initializes a potential list of random numbers. |
| 34 |
An index to this potential random number list is returned. |
| 35 |
*) |
| 36 |
|
| 37 |
PROCEDURE InitRandom () : CARDINAL ; |
| 38 |
|
| 39 |
|
| 40 |
(* |
| 41 |
KillRandom - Kills a complete list of random numbers. |
| 42 |
*) |
| 43 |
|
| 44 |
PROCEDURE KillRandom (RandomListIndex: CARDINAL) ; |
| 45 |
|
| 46 |
|
| 47 |
(* |
| 48 |
GetAndDeleteRandom - Returns a random number from the |
| 49 |
list and then it is deleted. |
| 50 |
Numbers 1..n will be returned if they exist, |
| 51 |
if 0 is returned then the list is empty. |
| 52 |
*) |
| 53 |
|
| 54 |
PROCEDURE GetAndDeleteRandom (RandomListIndex: CARDINAL) : CARDINAL ; |
| 55 |
|
| 56 |
|
| 57 |
(* |
| 58 |
AddRandom - places a list of numbers 1..n into the specified list. |
| 59 |
*) |
| 60 |
|
| 61 |
PROCEDURE AddRandom (RandomListIndex: CARDINAL; n: CARDINAL) ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
GetRand - returns a number between 0..n-1. |
| 66 |
This routine is independant from the above routines. |
| 67 |
*) |
| 68 |
|
| 69 |
PROCEDURE GetRand (n: CARDINAL) : CARDINAL ; |
| 70 |
|
| 71 |
|
| 72 |
(* |
| 73 |
SetSeed - use, n, as the seed to pseudo random numbers. |
| 74 |
*) |
| 75 |
|
| 76 |
PROCEDURE SetSeed (n: CARDINAL) ; |
| 77 |
|
| 78 |
|
| 79 |
(* |
| 80 |
GetSeed - return the seed used to create pseudo random numbers. |
| 81 |
*) |
| 82 |
|
| 83 |
PROCEDURE GetSeed () : CARDINAL ; |
| 84 |
|
| 85 |
|
| 86 |
END Chance. |