Method: Interval::Pitch.random
- Defined in:
- lib/interval.rb
.random(normal = false) ⇒ Object
if normal=true then only return notes you would “normally” see. what is the word for that, natural?
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/interval.rb', line 57 def random(normal=false) p = new p.notename_i = NOTE_NAMES_TO_I.values.rand p.octave = 0 accidentals = [] if normal accidentals = case p.notename when 'c', 'f' [0, 1] when 'e', 'b' [-1, 0] else [-1, 0, 1] end else accidentals = [-1, 0, 1] end p.accidental = accidentals.rand p end |