Use arc4random(3) for math.random(), okay jolan@

This commit is contained in:
pedro 2007-03-15 22:03:37 +00:00
parent 83544b1761
commit 098ff510f6
2 changed files with 23 additions and 2 deletions

View File

@ -1,9 +1,9 @@
# $OpenBSD: Makefile,v 1.27 2007/01/07 17:31:53 pedro Exp $
# $OpenBSD: Makefile,v 1.28 2007/03/15 22:03:37 pedro Exp $
COMMENT= "powerful, light-weight programming language"
DISTNAME= lua-5.1.1
PKGNAME= ${DISTNAME}p2
PKGNAME= ${DISTNAME}p3
CATEGORIES= lang
MASTER_SITES= http://www.lua.org/ftp/ \

View File

@ -0,0 +1,21 @@
$OpenBSD: patch-src_lmathlib_c,v 1.1 2007/03/15 22:03:37 pedro Exp $
--- src/lmathlib.c.orig Sun Mar 4 11:10:17 2007
+++ src/lmathlib.c Sun Mar 4 11:11:40 2007
@@ -181,7 +181,7 @@ static int math_max (lua_State *L) {
static int math_random (lua_State *L) {
/* the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
- lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
+ lua_Number r = (lua_Number)(arc4random()%RAND_MAX) / (lua_Number)RAND_MAX;
switch (lua_gettop(L)) { /* check number of arguments */
case 0: { /* no arguments */
lua_pushnumber(L, r); /* Number between 0 and 1 */
@@ -207,7 +207,7 @@ static int math_random (lua_State *L) {
static int math_randomseed (lua_State *L) {
- srand(luaL_checkint(L, 1));
+ arc4random_stir();
return 0;
}