tag:blogger.com,1999:blog-3939164541028317159.post8720624580600323624..comments2023-05-25T09:20:09.110-06:00Comments on Raphael's blog: A bashism a week: $RANDOM numbersUnknownnoreply@blogger.comBlogger4125tag:blogger.com,1999:blog-3939164541028317159.post-21844886763077887292012-12-13T08:23:57.489-06:002012-12-13T08:23:57.489-06:00Hi,
as an addendum to the advice about mktemp: let...Hi,<br />as an addendum to the advice about mktemp: let's be sure to remove the temporary files in the "proper way":<br /><br />TMP="$(mktemp)"<br />trap 'rm -f "$TMP" >/dev/null 2>&1' 0<br />trap "exit 2" 1 2 3 15<br />...<br /><br />from http://www.shelldorado.com/goodcoding/tempfiles.html<br /><br />BTW randomness and uniqueness are different things: if I pick two numbers randomly they CAN be the same number, if I want unique numbers I can use a strictly monotonic function which is surely not random at all.<br /><br />So, to make your argument even stronger: using random numbers as unique identifiers is wrong as a _policy_, regardless of the mechanism :)<br /><br />Sometimes you want unique like in the temp file example, but some other times you really want random and PIDs are usually not good enough as they are designed for uniqueness, in that case using /dev/urandom in some way looks OK to me if you need _portability_.<br /><br />The way I see it, the argument against $RANDOM for random numbers is not about quality, it is about context: $RANDOM is just not portable, but there's no harm to use it where it is properly supported.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3939164541028317159.post-17826562785167455682012-12-13T03:35:21.963-06:002012-12-13T03:35:21.963-06:00Not all of these are necessarily offenders – for e...Not all of these are necessarily offenders – for example, if they have #!/bin/mksh they aren’t… except if it occurs in a line with tmp… there’s indeed no excuse for not using mktemp(1).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3939164541028317159.post-87348646401617156202012-12-12T08:35:52.550-06:002012-12-12T08:35:52.550-06:00http://codesearch.debian.net/search?q=\%24RANDOM+f...http://codesearch.debian.net/search?q=\%24RANDOM+filetype%3Ashell<br /><br />It seems that debian has a few offendersAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3939164541028317159.post-84026220681414544992012-12-12T02:43:23.479-06:002012-12-12T02:43:23.479-06:00Indeed, reminds me of the password generator that ...Indeed, reminds me of the password generator that used $RANDOM:<br /><br />http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=659047<br /><br />Anonymousnoreply@blogger.com