Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- cordx=0
- cordy=0
- truecount=0
- totalcount=0
- radius=0
- counts=40000 ## SET HERE NUMBER OF POINTS TO TEST
- while [ $counts -gt $totalcount ]; do
- cordx=$RANDOM
- cordy=$RANDOM
- radius=$(echo "sqrt( $cordy ^2 + $cordx ^2)" | bc)
- if [ $radius -lt 32768 ]; then
- truecount=$(( $truecount + 1 ))
- fi
- totalcount=$(( $totalcount + 1 ))
- done
- echo "TOTAL COUNTS: $truecount"
- echo "TRUE COUNTS: $totalcount"
- echo -n "RATIO (percent): "
- echo "scale=10; ( $truecount/$totalcount ) * 100" | bc
- echo -n "Pi: "
- echo "scale=10; ( $truecount/$totalcount ) * 4" | bc
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement