Skip to main content
added 287 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

You could just do:

(( my_rnd = (RANDOM << 17) | (RANDOM << 2) | (RANDOM & 3) ))

That is, take all 15 bits of a first RANDOM, shifted 17 bits, another 15 bits of another RANDOM, shifted 2 bits, and an extra 2 bits of a third RANDOM (the lower ones, you could also use RANDOM >> 13 for the higher ones, which at least in older versions of bash were significantly more random).

You could just do:

(( my_rnd = (RANDOM << 17) | (RANDOM << 2) | (RANDOM & 3)))

You could just do:

(( my_rnd = (RANDOM << 17) | (RANDOM << 2) | (RANDOM & 3) ))

That is, take all 15 bits of a first RANDOM, shifted 17 bits, another 15 bits of another RANDOM, shifted 2 bits, and an extra 2 bits of a third RANDOM (the lower ones, you could also use RANDOM >> 13 for the higher ones, which at least in older versions of bash were significantly more random).

Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

You could just do:

(( my_rnd = (RANDOM << 17) | (RANDOM << 2) | (RANDOM & 3)))