--
--	Random-number utilities
--	Copyright (C) 2008 Adam Sampson <ats@offog.org>
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation, either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library.  If not, see
--	<http://www.gnu.org/licenses/>.
--

--** @module useful

#INCLUDE "course.module"

--{{{  PROC seed.from.timer
--* Initialise a random number generator's seed using a timer.
PROC seed.from.timer (TIMER tim, RESULT INT seed)
  SEQ
    tim ? seed
    seed := (seed >> 2) + 1
:
--}}}
--{{{  FUNCTION random.real32
--* Generate a random [@code REAL32].
-- The resulting value will be selected from the range [@code 0.0 .. range].
REAL32, INT FUNCTION random.real32 (VAL REAL32 range, VAL INT seed)
  REAL32 result:
  INT value, newseed:
  VALOF
    SEQ
      value, newseed := random (MOSTPOS INT, seed)
      result := (range * (REAL32 ROUND value)) / (REAL32 ROUND (MOSTPOS INT))
    RESULT result, newseed
:
--}}}
