bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $RANDOM not Cryptographically secure pseudorandom number generator


From: Ole Tange
Subject: Re: $RANDOM not Cryptographically secure pseudorandom number generator
Date: Wed, 2 Jan 2019 02:29:24 +0100

On Mon, Dec 31, 2018 at 8:12 PM Chet Ramey <address@hidden> wrote:
:
> Thanks for the patch. I'll take a look after I release bash-5.0. One
> question: can you reproduce the same random sequence by using the same
> seed? That's for backwards compatibility, even if the sequences themselves
> differ.

Yes. Seeding with a value will give the same sequence:

$ RANDOM=4; echo $RANDOM $RANDOM
21584 22135

$ RANDOM=4; echo $RANDOM $RANDOM
21584 22135

For backwards compatibility integers are supported, but they are
really parsed as strings. Strings make it easier to seed with more
than 64-bits:

RANDOM=`cat GPLv3.txt`

So these give the same value on 4.4.23, but differs with the patch applied:

RANDOM=$(echo 2^64 | bc );echo $RANDOM
RANDOM=$(echo 2^65 | bc );echo $RANDOM

RANDOM="foo"; echo $RANDOM
RANDOM="bar"; echo $RANDOM

RANDOM=2; echo $RANDOM
RANDOM=" 2.0"; echo $RANDOM
RANDOM=" 2.0noise"; echo $RANDOM


/Ole



reply via email to

[Prev in Thread] Current Thread [Next in Thread]