make mksh compatible to the AT&T ksh spec which says, according to

twkm (from #ksh on freenode), that $RANDOM is always an unsigned
15-bit decimal integer.

(RANDOM << 15 | RANDOM) thusly yields 30 bit, which is still more
than 36^5, so we can use it on the baselife CD to speed things up
This commit is contained in:
tg 2006-11-19 16:43:43 +00:00
parent 8adc4a2c56
commit c2e79abc08
4 changed files with 14 additions and 17 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.74 2006/11/12 10:44:41 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.75 2006/11/19 16:43:41 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R29 2006/11/12
@(#)MIRBSD KSH R29 2006/11/19
description:
Check version of shell.
category: pdksh

11
mksh.1
View File

@ -1,7 +1,7 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.67 2006/11/16 13:05:39 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.68 2006/11/19 16:43:42 tg Exp $
.\" $OpenBSD: ksh.1,v 1.116 2006/07/26 10:13:25 jmc Exp $
.\"
.Dd November 12, 2006
.Dd November 19, 2006
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -1550,14 +1550,13 @@ Every time
is referenced, it is assigned a pseudo-random number first.
By default, if available,
.Xr arc4random 3
is used to produce unsigned 31\-bit values (0\-2147483647)
is used to produce unsigned 15\-bit values (0\-32767)
whose quality depends on the operating environment.
If
.Ev RANDOM
is assigned a value, it is used as the seed to
.Xr srand 3
and subsequent references yield a semi-predictable sequence
of unsigned 15\-bit results (0\-32767) employing
and subsequent references yield a semi-predictable sequence from
.Xr rand 3 .
.It Ev REPLY
Default parameter for the
@ -5190,7 +5189,6 @@ Shell database.
Privileged shell profile.
.El
.Sh SEE ALSO
.Xr arc4random 1 ,
.Xr awk 1 ,
.Xr ed 1 ,
.Xr getopt 1 ,
@ -5206,6 +5204,7 @@ Privileged shell profile.
.Xr open 2 ,
.Xr pipe 2 ,
.Xr wait 2 ,
.Xr arc4random 3 ,
.Xr getopt 3 ,
.Xr nl_langinfo 3 ,
.Xr rand 3 ,

4
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.84 2006/11/16 13:35:00 tg Exp $"
#define MKSH_VERSION "R29 2006/11/12"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.85 2006/11/19 16:43:43 tg Exp $"
#define MKSH_VERSION "R29 2006/11/19"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>

12
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.32 2006/11/12 14:58:16 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.33 2006/11/19 16:43:43 tg Exp $");
/*
* Variables
@ -853,7 +853,7 @@ makenv(void)
* we return values from rand() instead of arc4random()
*/
#if HAVE_ARC4RANDOM
int use_rand = 0;
static int use_rand = 0;
#endif
/*
@ -919,13 +919,11 @@ getspec(struct tbl *vp)
case V_RANDOM:
vp->flag &= ~SPECIAL;
#if HAVE_ARC4RANDOM
if (use_rand)
#endif
setint(vp, (long) (rand() & 0x7FFF));
#if HAVE_ARC4RANDOM
if (!use_rand)
setint(vp, arc4random() & 0x7FFF);
else
setint(vp, arc4random() & 0x7FFFFFFF);
#endif
setint(vp, rand() & 0x7FFF);
vp->flag |= SPECIAL;
break;
case V_HISTSIZE: