aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/builtin.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2015-12-28 20:31:12 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-01-07 20:54:50 -0800
commitef31aa94f8673482fca3e23e4ea0e88c60014526 (patch)
tree87459a8bce0f1b51337028608031f671539559b8 /src/builtin.cpp
parentbc3260402ad26664f704734c6b7168b4c647e970 (diff)
clarify the documentation of builtin random
The random builtin command may or may not produce values with a truly random distribution. So make the documentation reflect that reality. Also, make the command consistent with similar shells (e.g., bash, zsh) which produce a range of [0..32767]. Resolves issue #1272.
Diffstat (limited to 'src/builtin.cpp')
-rw-r--r--src/builtin.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/builtin.cpp b/src/builtin.cpp
index 932cf1b8..991c33da 100644
--- a/src/builtin.cpp
+++ b/src/builtin.cpp
@@ -2345,7 +2345,6 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
switch (argc-w.woptind)
{
-
case 0:
{
long res;
@@ -2356,8 +2355,9 @@ static int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **arg
srand48_r(time(0), &seed_buffer);
}
lrand48_r(&seed_buffer, &res);
-
- streams.out.append_format( L"%ld\n", labs(res%32767));
+ // The labs() shouldn't be necessary since lrand48 is supposed to
+ // return only positive integers but we're going to play it safe.
+ streams.out.append_format(L"%ld\n", labs(res % 32768));
break;
}