From 8a183dac78a5076d421dcbff263c6d163fe2a7fc Mon Sep 17 00:00:00 2001 From: Charlie Date: Sun, 18 May 2014 15:13:37 -0400 Subject: added random(max: float): float support to windows --- lib/pure/math.nim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/pure/math.nim') diff --git a/lib/pure/math.nim b/lib/pure/math.nim index e4aecd272..24a2ec7fa 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -135,12 +135,11 @@ proc random*(max: int): int {.gcsafe.} ## which initializes the random number generator with a "random" ## number, i.e. a tickcount. -when not defined(windows): - proc random*(max: float): float {.gcsafe.} - ## returns a random number in the range 0..".} proc random(max: float): float = result = drand48() * max - + when defined(windows): + proc random(max: float): float = + # we are hardcodeing this because + # importcing macros is extremely problematic + # and because the value is publicly documented + # on MSDN and very unlikely to change + const rand_max = 32767 + result = (float(rand()) / float(rand_max)) * max proc randomize() = randomize(cast[int](epochTime())) -- cgit 1.4.1-2-gfad0