# HG changeset patch # User Adam Chlipala # Date 1309726217 14400 # Node ID 7f8ddcf12b2067b4d2b90727d8cd60f507275178 # Parent 4300592e68039f6028dcc7d42ab9415e2be78dc2 Change Basis.rand to use cryptographically secure generation diff -r 4300592e6803 -r 7f8ddcf12b20 src/c/urweb.c --- a/src/c/urweb.c Sun Jul 03 16:21:04 2011 -0400 +++ b/src/c/urweb.c Sun Jul 03 16:50:17 2011 -0400 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -3777,8 +3778,13 @@ } uw_Basis_int uw_Basis_rand(uw_context ctx) { - uw_Basis_int n = abs(rand()); - return n; + uw_Basis_int ret; + int r = RAND_bytes((unsigned char *)&ret, sizeof ret); + + if (r) + return abs(ret); + else + uw_error(ctx, FATAL, "Random number generation failed"); } void uw_noPostBody(uw_context ctx) {