-
Notifications
You must be signed in to change notification settings - Fork 1
/
mdg2abcRndN.sh
executable file
·61 lines (57 loc) · 2.36 KB
/
mdg2abcRndN.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#===================================================================================
#
# FILE: mdg2abcRndN.sh
#
# USAGE: mdg2abcRndN.sh <num>
#
# where <num> is the number of random MDG minuets to be generated, e.g., 50.
# *** NOTE: This script has to be in the same directory as mdg2abc.sh. ***
#
# DESCRIPTION: Used for generating <num> ABC files, each a Musical Dice Game (MDG)
# minuet based on the rules given in K. 516f or K. 294d or K. Anh. C 30.01
# (1792 publication attributed to W.A. Mozart by his publisher, Nikolaus
# Simrock).
#
# AUTHOR: J.L.A. Uro (justineuro@gmail.com)
# VERSION: 1.0.2
# LICENSE: Creative Commons Attribution 4.0 International License (CC-BY)
# CREATED: 2017.08.12 14:30:55 +8
# REVISION: 2017/11/20 15:35:58
#==================================================================================
#----------------------------------------------------------------------------------
# define the function genS() that randomly chooses an integer from 2 to 12, inclusive
#----------------------------------------------------------------------------------
genS() { # RANDOM randomly generates an integer from 0 to 32767
rnd=32768
until [ $rnd -lt 32758 ]
do
rnd=$[RANDOM]
if [ $rnd -lt 32758 ]; then echo $[rnd%11+2]; fi
done
}
#----------------------------------------------------------------------------------
# declare the variable "diceS" as an array
# diceS - array containing the 16 outcomes from input line
#----------------------------------------------------------------------------------
declare -a diceS
#----------------------------------------------------------------------------------
# generate the <num> random minuets
#----------------------------------------------------------------------------------
i=1
while [ $i -le $1 ]; do
#----------------------------------------------------------------------------------
# generate the random 16-sequence of outcomes of the 16 throws of two dice
#----------------------------------------------------------------------------------
for j in {0..15}; do
diceS[$j]=`genS`
done
#----------------------------------------------------------------------------------
# generate a minuet in ABC notation for the current diceS using mdg2abc.sh
#----------------------------------------------------------------------------------
./mdg2abc.sh ${diceS[*]}
i=`expr $i + 1`
done
#
##
####