The code from this page can be found in my online CVS server here, and here.
Category: Bashrand
And then Nemo wanted weighted random numbers
Nemo then wanted weighted random numbers, so this item has been added to this page. The following script selects a random element from a weight list of options… #!/bin/bash # Copyright (c) Michael Still 2002 # Released under the terms of the GNU GPL # In this case, Nemo wants to be able to specify…
The challenge and the result
So, I was at a CLUG meeting last night, and one of the speakers had a whole bunch of bash scripts for XDM theming. Anyway, he was using a perl script to generate the random selection of the theme elements, and me and my big mouth offered that it could be done in bash itself….
How good are bash random numbers anyway
How good are these random numbers anyway? I generated 100,000 random numbers between 1 and 10, and then had a look at their frequency: 1: 9964 2: 10009 3: 9978 4: 10015 5: 9997 6: 10020 7: 10011 8: 10008 9: 10006 10: 9992 I would say that this is probably close enough to random…
Getting a random number in bash
This script generates a bounded random number: #!/bin/bash # Generate a random number. Copyright (c) Michael Still 2002 # Released under the terms of the GNU GPL # # (Is it possible to copyright a single line of code?) # To quote from the rand manpage as to why we bound the random number this…
Getting an arbitary item from a list
This script gets the specified element form the list on the command line… #!/bin/bash # Select a specified item from a list. Copyright (c) Michael Still 2002 # Released under the terms of the GNU GPL # $1 is the number to get, $* except for $1 is the list of options, delimited # by…