Search

virtual dice on the linux terminal

Here is a script that will act like a dice, a six sided dice, on the terminal.
On running the script, it will display numbers between 1 and 6 randomly, random number of times and at the end settle to one number just as in a usual dice.

dice.sh :



Save the file as dice.sh, and give it execute permission



On executing the script, the terminal will be cleared and in the top center numbers will appear. Which will change a few times and then settle to one number.



If executed with out any arguments the script simulates the normal six sided dice and the maximum number of rolls for the dice is 10 i.e. it will generate between 1 to 10 numbers randomly before settling on the final number.

This can be modified by passing the maximum number required in the dice as the first argument and the maximum number of rolls required in the second argument i.e.



Meaning simulate a dice that has numbers 1-8 and generate 20 random numbers before settling to the final one.

No comments:

Post a Comment