Questions tagged [random]

UNIX random devices and utilities

There are some standard and some less known random devices in Unix systems. The random tag is used to discuss the behavior of these pseudo- and true-random-number-generator (prng, hwrng) devices and the usage of random numbers.

235 questions
561
votes
25 answers

How to generate a random string?

I would like to generate a random string (e.g. passwords, user names, etc.). It should be possible to specify the needed length (e.g. 13 chars). What tools can I use? (For security and privacy reasons, it is preferable that strings are generated…
landroni
  • 10,288
  • 12
  • 30
  • 48
224
votes
6 answers

How can I populate a file with random data?

How can I create a new file and fill it with 1 Gigabyte worth of random data? I need this to test some software. I would prefer to use /dev/random or /dev/urandom.
Stefan Lasiewski
  • 19,264
  • 24
  • 70
  • 85
162
votes
3 answers

When to use /dev/random vs /dev/urandom

Should I use /dev/random or /dev/urandom? In which situations would I prefer one over the other?
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
121
votes
12 answers

Generate random numbers in specific range

After googling a bit I couldn't find a simple way to use a shell command to generate a random decimal integer number included in a specific range, that is between a minimum and a maximum. I read about /dev/random, /dev/urandom and $RANDOM, but none…
BowPark
  • 4,811
  • 12
  • 47
  • 74
96
votes
3 answers

What does the letter 'u' mean in /dev/urandom?

I understand that reads to /dev/random may block, while reading /dev/urandom is guaranteed not to block. Where does the letter u come into this? What does it signify? Userspace? Unblocking? Micro? Update: Based on the initial wording of the…
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
57
votes
6 answers

Why can't tr read from /dev/urandom on OSX?

A colleague suggested creating a random key via the following command: tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 32 | xargs It gave me the error: tr: Illegal byte sequence I'm concerned that I do not have /dev/urandom on…
Kirk Woll
  • 1,117
  • 2
  • 9
  • 9
56
votes
10 answers

What's the fastest way to generate a 1 GB text file containing random digits?

I tried a bash script, but it took too long to create a simple 1 MB file. I think the answer lies in using /dev/random or /dev/urandom, but other posts here only show how to add all kinds of data to a file using these things, but I want to add only…
posixKing
  • 1,077
  • 2
  • 12
  • 13
40
votes
4 answers

Why does dd from /dev/random give different file sizes?

I am running the following command on an ubuntu system: dd if=/dev/random of=rand bs=1K count=2 However, every time I run it, I end up with a file of a different size. Why is this? How can I generate a file of a given size filled with random…
Daniel
  • 1,167
  • 4
  • 13
  • 17
35
votes
6 answers

Tool for measuring entropy quality?

Is there a tool available for Linux systems that can measure the "quality" of entropy on the system? I know how to count the entropy: cat /proc/sys/kernel/random/entropy_avail And I know that some systems have "good" sources of entropy (hardware…
Dustin Kirkland
  • 2,543
  • 2
  • 17
  • 15
32
votes
3 answers

Run commands at random

I want to run one of the two commands C1 and C2 at random. How do I do that on commandline (bash)? Will appreciate if a one-liner is possible.
user13107
  • 5,265
  • 10
  • 45
  • 62
31
votes
3 answers

Create random data with dd and get "partial read warning". Is the data after the warning now really random?

I create a 1TB file with random data with dd if=/dev/urandom of=file bs=1M count=1000000. Now I check with kill -SIGUSR1 the progress and get the following: 691581+0 Datensätze ein 691580+0 Datensätze aus 725174190080 Bytes (725 GB) kopiert,…
delete
  • 313
  • 1
  • 3
  • 7
26
votes
6 answers

Using /dev/random, /dev/urandom to generate random data

I'm looking for ways to use /dev/random (or /dev/urandom) from the command line. In particular, I'd like to know how to use such a stream as stdin to write streams of random numbers to stdout (one number per line). I'm interested in random numbers…
kjo
  • 14,779
  • 25
  • 69
  • 109
25
votes
4 answers

Create unique random numbers (UUIDs) in bash

I want to create random unique numbers (UUIDs) as the following node.id=ffffffff-ffff-ffff-ffff-ffffffffffff First I tried this $ rndnum=` echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM` $ echo $rndnum 30380-echo…
yael
  • 12,598
  • 51
  • 169
  • 303
25
votes
3 answers

Why writing to /dev/random does not make parallel reading from /dev/random faster?

Typically reading from /dev/random produces 100-500 bytes and blocks, waiting for an entropy to be collected. Why doesn't writing information to /dev/random by other processes speed up reading? Shouldn't it provide the required entropy? It can be…
Vi.
  • 5,528
  • 7
  • 34
  • 68
23
votes
2 answers

What keeps draining entropy?

If I do watch cat /proc/sys/kernel/random/entropy_avail I see that my systems entropy slowly increases over time, until it reaches the 180-190 range at which point it drops down to around 120-130. The drops in entropy seem to occur about every…
wingedsubmariner
  • 2,884
  • 1
  • 17
  • 21
1
2 3
15 16