Tag Info

Hot answers tagged

19

That's exactly the difference between /dev/random and /dev/urandom -- random uses the entropy pool, which gathers noise from a bunch of sources and keeps track of "how much" noise is currently in the pool, so random knows how much high-quality randomness it can generate. Since the entropy pool has a finite amount of noise, reading from random might need to ...


18

You're observing a combination of the peculiar behavior of dd with the peculiar behavior of Linux's /dev/random. Both, by the way, are rarely the right tool for the job. Linux's /dev/random returns data sparingly. It is based on the assumption that the entropy in the pseudorandom number generator is extinguished at a very fast rate. Since gathering new ...


18

On most unices: head -c 1M </dev/urandom >myfile If your head doesn't understand the M suffix: head -c 1048576 </dev/urandom >myfile If your head doesn't understand the -c option (it's common but not POSIX; you probably have OpenBSD): dd bs=1024 count=1024 </dev/urandom >myfile Do not use /dev/random on Linux, use /dev/urandom.


17

Assuming that pseudo-random data is sufficient, dd if=/dev/urandom of=target-file bs=1M count=1000000 will do what you want. dd(1) will read blocks of data from an input file and write them to an output file. The command line language is a little quirky, but it is one of those really useful tools worth mastering the basics of. In this case if is input ...


16

It writes until the disk is full (usually there is still some space reserved for the root user). But as the pool of random data is limited, this could take a while. If you need a certain amount of random data, use dd. For 1MB: dd if=/dev/random iflag=fullblock of=$HOME/randomFile bs=1M count=1 Other possibilities are mentioned in answers to a related ...


14

Linux has two random number generators available to userspace, /dev/random and /dev/urandom. /dev/random is a source of "true" randomness - i.e. it is not generated by a pseudo-random number generator. Entropy is fed into this by the input driver and the interrupt handler, through the functions add_input_randomness and add_interrupt_randomness. Processes ...


12

It will eventually. In: cat /dev/random | strings --bytes 1 | tr -d '\n\t ' cat will never buffer, but it's superfluous anyway as there's nothing to concatenate here. < /dev/random strings --bytes 1 | tr -d '\n\t ' strings though, since its output is not longer a terminal will buffer its output by blocks (of something like 4 or 8kB) as opposed to ...


11

Based on the error message that you get, I don't think /dev/urandom is the problem. If it were, I'd expect an error like "no such file or directory". I searched for the error message you got and found this, which seems like it might be relevant to your issue: http://nerdbynature.de/s9y/?176 Basically, specify the locale by prepending the tr command with ...


10

From man 4 random on a RHEL 5 box: When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. I get files of size 213 bytes on that machine. Back to man 4 random: When read, /dev/urandom device will return as many bytes as are requested. I get 2048 bytes from ...


7

See man bash, PARAMETERS section, Shell Variables subsection: RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset. ...


7

Your example data and constraints actually only allow a few solutions—you must play John B. every other song, for example. I'm going to assume your actual full playlist isn't essentially John B, with random other stuff to break it up. This is another random approach. Unlike @frostschutz's solution, it runs quickly. It does not guarantee a result that ...


7

GnuPG consumes several bytes from /dev/random for each random byte it actually uses. You can easily check that with this command: start cmd:> strace -e trace=open,read gpg --armor --gen-random 2 16 2>&1 | tail open("/etc/gcrypt/rngseed", O_RDONLY) = -1 ENOENT (No such file or directory) open("/dev/urandom", O_RDONLY) = 3 read(3, ...


6

Your suggestion that this difference is because openssl uses /dev/urandom and gpg uses /dev/random is correct. You can watch the available entropy going down while generating keys with gpg using: watch -n 1 cat /proc/sys/kernel/random/entropy_avail I used a program for generating the description of the steps for setting up a OpenGPG smart card with gpg, ...


5

Why does dd drop data? ... Gilles has posed this engaging question about dd: When is dd suitable for copying data? (or, when are read() and write() partial) Here is an excerpt from that question:     ...it's not difficult to put dd at fault; for example try this code:*         yes | dd of=out bs=1024k count=10     and check the size of the out file (it's ...


5

In bash you can do it like this: sleep $(($RANDOM%3)) && some_command thus waiting between 0 and 2 seconds before executing the command. Or choose another interval. Or if $RANDOM is not available you can try jot: sleep `jot -r 1 0 3` && some_command Sure, the random waiting plus executing is not provided by a single binary, but close. ...


5

You misunderstand regex syntax. [16-32] does not mean "match 16, 17, ... or 32". It means "match one character which is either 1 or 2 or in the range 6-3" (which is not a valid range, hence the error). It's possible to write a regex to match a range of integers, but it's complex and error prone. In your case, it would be much easier to use nmap's ...


5

You are writing 512 bytes into a file and execute it. So the outcome could be anything a program with 512 bytes could possibly do. What that is depends on your machine. But 512 bytes are plenty of instructions, so basically everything could have happened like changing the root password, creating random files or generating a tar archive containing the source ...


4

If you want finer-grained control than maxschlepzig's nice bash incantations, it's a reasonably easy thing to just code up: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <time.h> int main(int argc, char**argv){ useconds_t mdelay=0, delay; if (argc<3){ fprintf(stderr,"%s <delay (in ...


4

find . -type f | shuf | # shuffle the input lines, i.e. apply a random permutation nl -n rz | # add line numbers 000001, … while read -r number name; do ext=${name##*/} # try to retain the file name extension case $ext in *.*) ext=.${ext##*.};; *) ext=;; esac mv "$name" "../randomized/${name%/*}/$number$ext" done Replace mv by ln or ln ...


4

You can do something like this in Bash: $ (( RANDOM%2 == 0 )) && C1 || C2 This will generate a random number, either 0 or 1. If it's a 0, then C1 runs, otherwise C2 runs if it isn't. example $ (( RANDOM%2 == 0 )) && echo 0 || echo 1 1 $ (( RANDOM%2 == 0 )) && echo 0 || echo 1 0 NOTE: The first character, $, is the prompt. ...


4

Entropy is not only lost via /dev/{,u}random, the kernel also takes some. For example, new processes have randomized addresses (ASLR) and network packets need random sequence numbers. Even the filesystem module may remove some entropy. See the comments in drivers/char/random.c. If you need to watch the entrophy pool, do not use watch cat, that will consume ...


4

If I had to apply that shuffling to a deck of playing card, I think I'd first shuffle the deck, then display the cards in a row before my eyes and processing from left to right, wherever there are adjacent clubs or heart... move all but one of those at random somewhere else (though not next to another one of the same type). For example, with a hand like 🂡 ...


4

Summary: dd is a cranky tool which is hard to use correctly. Don't use it, despite the numerous tutorials that tell you so. dd has a “unix street cred” vibe attached to it — but if you truly understand what you're doing, you'll know that you shouldn't be touching it with a 10-foot pole. dd makes a single call to the read system call per block (defined by ...


3

Software random number generators are not the only source of entropy in the system. Actually they are not sources of entropy at all - software RNGs use external entropy sources to supply entropy to the system. The real source is always a physical one (be it a dedicated hardware RNG, temperature sensors, audio input, timing of network packets, user inputs or ...


3

There are various solutions for generating entropy. For example haveged (which I'm very happy with myself), timer_entropyd, audio-entropyd, etc. etc. they usually yield enough entropy for most applications that use /dev/random. If you want to go all out, there are also hardware random generators, available as USB sticks. Although they may yield less entropy ...


3

This RNG comes as part of a Trusted Platform Module. Unless your computer was part of an order for a large organization, the TPM is disabled by default, because it can make your computer unbootable if misconfigured, and because it can make your computer more traceable¹. If you want to use the RNG, you'll have to enable it in the BIOS. The Thinkpad wiki has ...


3

dd if=/dev/urandom of=/dev/sda, or simply cat /dev/urandom >/dev/sda, isn't the fastest way to fill a disk with random data. Linux's /dev/urandom isn't the fastest cryptographic RNG around. Is there an alternative to /dev/urandom? has some suggestions. In particular, OpenSSL contains a faster cryptographic PRNG: openssl rand $(</proc/partitions awk ...


3

From http://en.wikipedia.org/wiki//dev/random#Linux: "When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered." Edit: Looks like Michael beat me to it!


2

There's nothing Unix specific here... import random, os input_path = "/home/badp/Youtube/" #absolute path for simplicity output_path = "./playlist" files = os.listdir(input_path) #assume all files in the same folder for simplicity random.shuffle(files) os.mkdir(output_path) os.chdir(output_path) i = 0 for filename in files: os.link( ...



Only top voted, non community-wiki answers of a minimum length are eligible