Re: Restrict RAND to producing 63 random bits

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

 



On Thu, Jul 20, 2023 at 02:31:29PM -0400, Robert Moskowitz wrote:

> This seems to generate a random number between 1 and 2^63-1
> 
> And print a hex
> 
> printf "%X\n" $(shuf -rn 1 -i 1-9223372036854775807 
> --random-source=/dev/urandom)
> 
> I don't know if I can trust this as a real random number, but it IS 
> taking its source from urandom.  Plus it is "only" for serial number thus

OpenSSL typically just uses /dev/urandom also.  If you prefer using
OpenSSL, and you're on 64-bit CPU, "bash" or "ksh" can do the requisite
arithmetic:

    r64="0x$(openssl rand -hex 8)" || exit 1
    r63=$(printf "%016x\n" $(( $r64 & (2**63-1) )) )
    ... do stuff with $r63 ...

-- 
    Viktor.




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

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux