Random number seed generation/storage on startup?

Hi there,
I'm wanting a really simple way to generate a new random number seed on each boot?

Thank you :slight_smile:

use /dev/random or /dev/urandom ?


Thanks for the reply.
I mean like a really simple rc.local style command?
Will that happen automatically?
I'm pretty fresh at OpenWRT, and have a lot to learn.

You didn't provide enough information in your question, like what size and range of random number? How will it be used? How do you want to store the random number (e.g. in a file)?

You can see details in the accepted answer to this question for generating different size (range) numbers.

Like the already existing urandom-seed package that is installed by default to OpenWrt...

Like I said yesterday

echo $RANDOM

There are tons of literature about random number generation in Linux, and the issues with seed initialization. This subject has been debated over and over again, and lots of people have spent many hours working on it.

Unless you are way more specific about the issue you are trying to fix, or have a very innovative ideas, there is not much else to be said.


$RANDOM would be a bashism, not defined in POSIX shell (yes, OpenWrt's busybox seems to provide it right now, but relying on that isn't good practice, not that the entropy would be any good either).


it seemed like the simplest way to give a random number (I know it's a little solution), but in context it can be useful

The question is not about getting a random number, but about seeding the random number generator with some entropy to ensure "more randomness", which is traditionally a problem in an embedded headless device, which can boot from a pretty static situation (and boots without a real time).

There are lots of discussions in the old OpenWrt bug tracker, new bug tracker, old forum and this new forum about that. E.g.

and e.g. this from year 2011...

Like I said earlier, OpenWrt has currently its own method of storing a new random seed after a boot for the next boot. But the importance of that is reduced after kernel moved to the new blake2 based randomness. (kernel does not even report the entropy count, like earlier)

There are also solutions like haveged to provide additional entropy during the router operations.

I used "chaoskey", a hardware device in WRT3200ACM mwlwifi my router for a while, as mwlwifi did not provide entropy like ath9k :wink:


True, then again "posix shell" seems to be a subset of useful commands that aims at always falling short a bit, as if intended to steer people away from using shell for more than short scripts... Bash might not be standard, but it offers a considerably richer set of commands, and I heard z-shell also offers decent goodies. But I digress and will stop.

1 Like

When Debian moved from bash as /bin/sh provider to dash, I converted quite a lot of scripts (including quite sophisticated ones) to pure POSIX shell. Most bashisms were rather low hanging fruits, which had to be done differently, but were effectively equivalent and not really more complicated or less useful. Only few instances really profitted from advanced bash specific features (bash arrays or quoting differences). In my experience, it's mostly a question of knowing the differences and avoiding unnecessary bashisms, being aware of the details.

If you are dealing with slow systems (in my case a SPARCstation 20 with a single 50 MHz SuperSPARC core until relatively 'recently'), you do see that bash is relatively slow (it's not nice to wait >>20s for a ssh login with bash as user shell, when busybox ash, dash, pdksh, posh, mksh start instantly (<0.5s), no, this is not exaggerating). As a consequence, I did successfully review, convert and validate almost all scripts I'm responsible for to pure POSIX sh (avoiding dashisms and busyboxisms as well), it's possible. The only remaining piece is a rather complex one, I inherited from someone who wrote it as a showcase to play with new bash features - and even there are so many low hanging fruits that it's really tempting to start 'fixing' it...

Yes, bash or zsh specifics do have advantages as well, but while you may expect bash to be installed (albeit not as /bin/sh) on 'most' systems, zsh has a much smaller deployment percentage (mostly enthusiasts), making it a rather heavy dependency (e.g. your scripts would have to make really good coffee and ice cream, to make me accept installing yet-another-fringe-interpreter for it (remember ruby, lua, rexx2, ...?).