random

最後更新: 2019-12-19

 


random Source

  • keyboard strokes
  • mouse movement
  • sound via the microphone

random 與 urandom

random

very high quality randomness

only return random bytes within the estimated number of bits of noise in the entropy pool.

When the entropy pool is empty, reads will block until additional environmental noise is gathered.

c 1:8

urandom

It is a pseudo random number generator

as many bytes as are requested( u --> unlocked )

原理 reuses the internal pool to produce more pseudo-random bits.

c 1:9

hardware random number generators

/dev/hwrng

Such devices are often based on microscopic phenomena that generate

low-level, statistically random "noise" signals, such as thermal noise, the photoelectric effect

TRNG: true random number generator

其他資料

# A full entropy pool size (bits)

cat /proc/sys/kernel/random/poolsize

4096

# 可用的 random bit

cat /proc/sys/kernel/random/entropy_avail

151

# read_wakeup_threshold

waking up processes that sleep waiting for entropy from /dev/random

# write_wakeup_threshold

wake up processes that do a select(2) or poll(2) for write access to /dev/random.

# uuid

每次 read 都會有不同的 uuid

# boot_id

當時產上一次的

 


Full the pool

 

read_wakeup_threshold 與 entropy_avail 的關係:

max entropy_avail<read_wakeup_threshold * 3

min. entropy_avail>read_wakeup_threshold * 2

保存的 entropy:

sysctl -w kernel.random.read_wakeup_threshold=1365

 


生成 Random

 

# 3 位數的 random number

tr -cd 0-9 </dev/urandom | head -c 3

透過系的的 urandom:

head -c 200 /dev/urandom | md5sum

透過 bash shell 的 Verable:

echo $RANDOM


Doc

man 4 random

 

 

Creative Commons license icon Creative Commons license icon