From 098ff510f6344bcad3c071ad0577ce6145e41464 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 15 Mar 2007 22:03:37 +0000 Subject: [PATCH] Use arc4random(3) for math.random(), okay jolan@ --- lang/lua/Makefile | 4 ++-- lang/lua/patches/patch-src_lmathlib_c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lang/lua/patches/patch-src_lmathlib_c diff --git a/lang/lua/Makefile b/lang/lua/Makefile index 2c018e3ecf9..66065ef6c8a 100644 --- a/lang/lua/Makefile +++ b/lang/lua/Makefile @@ -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/ \ diff --git a/lang/lua/patches/patch-src_lmathlib_c b/lang/lua/patches/patch-src_lmathlib_c new file mode 100644 index 00000000000..89483ca7665 --- /dev/null +++ b/lang/lua/patches/patch-src_lmathlib_c @@ -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; + } +