Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: MUDDOG
My dice throwing program in BASIC on my MSDOS 8086 computer was nice and simple, using the random number generator.

Rolling Dice in Linux with Bash:

#!/usr/bin/bash
DIE1=$(( ( RANDOM % 6 )  + 1 ))
DIE2=$(( ( RANDOM % 6 )  + 1 ))
echo -n "Your roll is ${DIE1} and ${DIE2} "
echo -n "and your total is "
echo ${DIE1}+${DIE2} | bc

$ rolldice
Your roll is 2 and 4 and your total is 6
$ rolldice
Your roll is 6 and 4 and your total is 10
$ rolldice
Your roll is 1 and 2 and your total is 3
 

 

35 posted on 11/22/2014 8:36:54 PM PST by zeugma (The act of observing disturbs the observed.)
[ Post Reply | Private Reply | To 16 | View Replies ]


To: zeugma
Nice!

I don't think I have Linux though.

36 posted on 11/22/2014 8:44:38 PM PST by MUDDOG
[ Post Reply | Private Reply | To 35 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson