Commit e69855506fdebfd6e050b5f73109cadc7f468036

Thomas de Grivel 2023-12-18T16:51:40

fix f64_random

diff --git a/libc3/f64.c b/libc3/f64.c
index 45e62dd..0221fe7 100644
--- a/libc3/f64.c
+++ b/libc3/f64.c
@@ -90,7 +90,8 @@ f64 * f64_random (f64 *x)
 {
   u64 i;
   const u64 max = ((u64) 1 << 53) - 1;
-  u64_random_uniform(&i, max);
+  u64_random(&i);
+  i &= max;
   *x = (f64) i / max;
   return x;
 }
diff --git a/libc3/u.c.in b/libc3/u.c.in
index f212f01..5798376 100644
--- a/libc3/u.c.in
+++ b/libc3/u.c.in
@@ -94,23 +94,12 @@ u_bits$ * u_bits$_random (u_bits$ *u)
 
 u_bits$ * u_bits$_random_uniform (u_bits$ *u, u_bits$ max)
 {
-  u_bits$ rest;
-  u_bits$ result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("u_bits$_random_uniform: not implemented");
+  assert(! "u_bits$_random_uniform: not implemented");
+  return NULL;
 }
 
 #else
diff --git a/libc3/u16.c b/libc3/u16.c
index b518653..309e6a0 100644
--- a/libc3/u16.c
+++ b/libc3/u16.c
@@ -94,23 +94,12 @@ u16 * u16_random (u16 *u)
 
 u16 * u16_random_uniform (u16 *u, u16 max)
 {
-  u16 rest;
-  u16 result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("u16_random_uniform: not implemented");
+  assert(! "u16_random_uniform: not implemented");
+  return NULL;
 }
 
 #else
diff --git a/libc3/u32.c b/libc3/u32.c
index 7233179..f09d551 100644
--- a/libc3/u32.c
+++ b/libc3/u32.c
@@ -94,23 +94,12 @@ u32 * u32_random (u32 *u)
 
 u32 * u32_random_uniform (u32 *u, u32 max)
 {
-  u32 rest;
-  u32 result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("u32_random_uniform: not implemented");
+  assert(! "u32_random_uniform: not implemented");
+  return NULL;
 }
 
 #else
diff --git a/libc3/u64.c b/libc3/u64.c
index cf2ef47..082112e 100644
--- a/libc3/u64.c
+++ b/libc3/u64.c
@@ -94,23 +94,12 @@ u64 * u64_random (u64 *u)
 
 u64 * u64_random_uniform (u64 *u, u64 max)
 {
-  u64 rest;
-  u64 result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("u64_random_uniform: not implemented");
+  assert(! "u64_random_uniform: not implemented");
+  return NULL;
 }
 
 #else
diff --git a/libc3/u8.c b/libc3/u8.c
index f64bd2f..ee10592 100644
--- a/libc3/u8.c
+++ b/libc3/u8.c
@@ -94,23 +94,12 @@ u8 * u8_random (u8 *u)
 
 u8 * u8_random_uniform (u8 *u, u8 max)
 {
-  u8 rest;
-  u8 result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("u8_random_uniform: not implemented");
+  assert(! "u8_random_uniform: not implemented");
+  return NULL;
 }
 
 #else
diff --git a/libc3/uw.c b/libc3/uw.c
index dd77b80..2304b3f 100644
--- a/libc3/uw.c
+++ b/libc3/uw.c
@@ -94,23 +94,12 @@ uw * uw_random (uw *u)
 
 uw * uw_random_uniform (uw *u, uw max)
 {
-  uw rest;
-  uw result;
-  assert(u);
-  assert(max);
-  rest = max;
-  result = 0;
-  while (rest > (u32) -1) {
-    rest >>= 32;
-    result <<= 32;
-    result += arc4random();
-  }
-  if (rest) {
-    result <<= 32;
-    result += arc4random_uniform(rest);
-  }
-  *u = result;
-  return u;
+  // TODO
+  (void) u;
+  (void) max;
+  err_puts("uw_random_uniform: not implemented");
+  assert(! "uw_random_uniform: not implemented");
+  return NULL;
 }
 
 #else