Commands tagged trng (1)

  • Do not use this in production! This is a true hardware random number generator using your system as the entropy source. It models flipping a coin by pitting a fast clock (the CPU) against a slow clock (the RTC). The CPU models the coin flipping head over tails during flight and the RTC models the duration of the coin's flight in the air. A timer is set 1 millisecond into the future and a bit is flipped as fast as possible before the timer expires. 256 bits are collected then hashed with SHA-256 to whiten the data and ensure uniformity. This makes some assumptions however. It assumes that your system is not compromised. It assumes your system is generating enough interrupts for the kernel scheduler to be unpredictable on what gets CPU priority. It assumes that your installed sha256sum(1) command is correctly implemented. Just because you can, doesn't mean you should. Use your system's RNG (EG, /dev/urandom) instead. Show Sample Output


    1
    trng() { zmodload zsh/datetime; local flips=""; while ((${#flips}<256)); do local coin=0; local t=$((EPOCHREALTIME+0.001)); while (($EPOCHREALTIME<$t)); do ((coin^=1)); done; flips+=$coin; done; local h=($(print "$flips"|sha256sum));
    atoponce · 2025-11-24 18:13:40 0

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

list block devices
Shows all block devices in a tree with descruptions of what they are.

Remove a range of lines from a file

Show one line summaries of all DEB packages installed on Ubuntu based on pattern search
I sometimes want to know what packages are installed on my Ubuntu system. I still haven't figured out how to use aptitude effectively, so this is the next best thing. This allows finding by name. The grep '^ii' limits the display to only installed packages. If this is not specified, then it includes listing of non-installed packages as well.

Show current working directory of a process

Synchronize date and time with a server over ssh
using -u is better for standardizing date output and timezones, for servers in different timezones.

Remove all unused kernels with apt-get
TIMTOWTDI

Generate a Change Log with git
Generate a changelog between the v1 and v2 tags

Rename all .jpeg and .JPG files to have .jpg extension
the "i" controls case sensitiveness. It's slightly inefficient since it uselessly renames .jpg to .jpg, but that's more than compensated by launching only one process instead of two, besides being shorter to write.

Remove a range of lines from a file
Deletes lines from START to END, inclusive. For example +4,10d will delete line 4, 5, ..., 10. Just like the vi command :4,10d does it.

Cleanly manage tempfiles in scripts
Cleanly create tempfiles using mktemp and remove them using traps instead of removing them in the end of the script. This way, you make sure the tempfiles are removed properly even if the script is killed or interrupted. For a user script in KDE4, you can set TMPROOT using : $ TMPROOT=$(kde4-config --path tmp)


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: