Here’s some mathematica code that will generate random musical tunes. Sometimes they come out half decent… sometimes.
<<Miscellaneous`Music`;
(* randomwalk: generates a sequence where each element is within 2*range of the
previous one. *)
randomwalk[length_, range_] := Module[{ret={0}, cur=0},
Do[AppendTo[ret, cur += Floor[Random[]*(2r+1)]-r], {n}];
ret];
(* scaletone: index into a scale (of cents), incorporating negatives *)
scaletone[scale_, index_] :=
scale[[ Mod[index, Length[scale]] + 1 ]]
+ 1200*Floor[index/Length[scale]];
(* palendromify: append the reverse of a list to itself *)
palendromify[list_] := Join[list, Reverse[list]];
(* randomtune: generate a nice random song *)
randomtune[scale_, range_, notes_, length_] :=
Scale[scaletone[scale, palendromify[randomwalk[notes, range]]]], 440, length];
(* example *)
Show[randomtune[JustMajor, 3, 32, 10]]
Try it out. Or if you don’t have mathematica, then… don’t try it out.
