summary refs log tree commit diff stats
path: root/lib/pure/math.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-05-25 21:20:26 +0200
committerAraq <rumpf_a@web.de>2014-05-25 21:20:26 +0200
commit04a1555f4aa90eadc4d974a04abbf50d1e8b7134 (patch)
tree2e26496b1158a1b14c8c0bb307c670ea2d100cb5 /lib/pure/math.nim
parentb230303fd6dd1d593aecf792ee8f72552e7e5946 (diff)
parent1d6c05edc399e31919114f2b07519ae79ae1b804 (diff)
downloadNim-04a1555f4aa90eadc4d974a04abbf50d1e8b7134.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'lib/pure/math.nim')
-rw-r--r--lib/pure/math.nim21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index e4aecd272..78ea02cbf 100644
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -135,12 +135,12 @@ 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..<max. The sequence of
-    ## random number is always the same, unless `randomize` is called
-    ## which initializes the random number generator with a "random"
-    ## number, i.e. a tickcount. This is currently not supported for windows.
+proc random*(max: float): float {.gcsafe.}
+  ## returns a random number in the range 0..<max. The sequence of
+  ## random number is always the same, unless `randomize` is called
+  ## which initializes the random number generator with a "random"
+  ## number, i.e. a tickcount. This has a 16-bit resolution on windows
+  ## and a 48-bit resolution on other platforms.
 
 proc randomize*() {.gcsafe.}
   ## initializes the random number generator with a "random"
@@ -205,7 +205,14 @@ when not defined(JS):
     proc drand48(): float {.importc: "drand48", header: "<stdlib.h>".}
     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()))