How to generate numbers from the Fibonacci Sequence?

    Apr 22 2011 | 5:36 pm
    hey i'm trying to create a composition with midi, at the moment ive managed to figure out how to generate random numbers but i wanted to make it generate numbers from the Fibonacci sequence, is this possible and how would i go about programming it to do this?

    • Apr 22 2011 | 7:15 pm
      I would put numbers from the Fibonacci sequence in a coll or table, and select them randomly.
    • Apr 22 2011 | 8:02 pm
      Two immortal rabbits + single malt scotch and just let nature take its course
    • Apr 22 2011 | 8:03 pm
      okay thank you! how do i go about putting in a coll or table into my patcher - sorry i am very new to max msp
    • Apr 22 2011 | 10:27 pm
      Please examine carefully the used objects by alt-clicking them (open helpfile) to see how they work... hth o
    • Apr 23 2011 | 1:56 am
      As long as I'm already musing about the fact that pedagogy and pedantic have the same root, I might as well post this improvement to the patch above (my changes noted in red):
      If you're wondering what to do with that text, look at this thread:
    • Apr 23 2011 | 5:44 am
    • Apr 23 2011 | 7:39 am
      @ Chris Muir: thanks for your improvement. I was not aware of the funnel and the listfunnel objects until today...
    • Apr 23 2011 | 8:24 am
      Thank you all! this has been a HUGE help!
      is there a way to make it so the numbers play in a particular order that i choose or must it be done in random?
    • Apr 23 2011 | 4:52 pm
      Hi If you send [coll] a pair of numbers it stores the second value at the 'first' index; if you send [coll] individual numbers it outputs the value at that index, so sending [coll] '2' will output the value stored at index# 2. So, if you want values from indices 1, 2, 3, 6, 9 and 6, send it a stream made up of those numbers (not a list I think)....
      @Chris pedagogue v pedant LOL niiiiice. For the record, it's really cool to see someone appending/varying/improving another's patch, used to happen a lot here but not so much recently.
    • Apr 23 2011 | 5:09 pm
      what he said ... plus some fixes.
    • Apr 25 2011 | 3:53 am
      I became interested in 'sacred geometry' through music, and interested in general math through geometry, and programming through general I've been meaning to do this for a while. It was one of the first things I tried to do when I started maxing a few months ago, but naturally I got the stack overflow message and quickly got discouraged.
      I just found a workaround using messages, bangs and delays. This is just about my messiest patch yet, as I'm still fumbling for a more elegant method, and I opted for the old quick and dirty style. This is an actual fibonacci generator, rather than a preset list/recall function.
      If you let it go long enough it starts to generate negative numbers (I'm not sure why, perhaps some cap on the length of message boxes?). It's accurate to the 46th iteration, I think, but it breaks down after that.
      If anyone knows why it does that, and can fix it, I'd be grateful. I'm on the right track, I think, but I lack the experience to troubleshoot beyond this. I'm sure the community could find uses for an an accurate fibonacci generator.
      Est voila!
    • Apr 25 2011 | 5:21 am
      Here's how I generate random Fibonacci numbers in my patches:
    • Apr 25 2011 | 8:06 am
      Well that is certainly much simpler than my way, to say the least.
      On a positive note, I'm learning more about using coll, and I think I've found a much better workaround to avoid stack overflows. Given some work I think I'm going to be able to bypass the 31 digit limit for other fractal numbers, with a little help from coll and some funky math. If it works I'll post here.
      Thanks for the benefit of your experience, Roth.
    • Apr 25 2011 | 8:39 am
      Or you can use the formula for generating fibonacci numbers and then you don't have to rely on your coll's memory capacity to generate the numbers (or limit yourself to how many numbers you have inserted in the coll before you start):
    • Apr 25 2011 | 10:39 am
      a 6th version anyone?
      btw, finbonacci numbers are SO useless for music. ^^
    • Apr 25 2011 | 4:50 pm
      All these Fibonacci generators are cool, but with only the first 45 numbers in the Fibonacci series fitting within the constraints of a Max integer, I think that the table approach is the best bet.
      (and I do have a bucket-based Fibonacci generator somewhere)
    • Apr 25 2011 | 8:08 pm
      @Chris~ I wish I'd known about bucket when I started, thanks.
      @Roman~ The numbers get real big real fast, so I'd agree with you if it weren't for the [%] object. Between that and [round] I can think of quite a few uses for spicing up some generative synths/random sequencers.
    • Apr 25 2011 | 8:13 pm
      btw, finbonacci numbers are SO useless for music.
      yeah so are major and minor scales. and chords.
    • Apr 25 2011 | 9:23 pm
      It took a little digging, but I found my bucket-based version:
    • Apr 26 2011 | 4:59 am
      How does it work?
    • Apr 26 2011 | 6:23 am
      yeah, but my bucket version is greener than yours.
    • Apr 26 2011 | 3:35 pm
      There's a generator for Lucas Sequences in the CNMAT MMJ Depot, downloadable here:
      Fibonacci numbers are a subset of that.
    • May 16 2011 | 10:36 am
      I generated my own piece of JS for running Fibonacci and have hit upon an interesting Max query based upon the size of a list of numbers:
      I can run the sequence up to ~150 values quite happily. I then decided to store a few variables in [coll]. Namely index, value, reciprocal. When I pack these three variables into a list, the value and reciprocal go AWOL at ~50th index.
      As all three values use 32bit integers or floats, does the potential range of an int/float become limited when all are appended to the same list? i.e. does our 32bits get divided up between all list members?
      Silly question this may be, but it's something I've never considered before and perhaps is something to bear in mind when handling lists of large numbers in the future....
    • May 16 2011 | 6:12 pm
      Max uses a signed 32 bit word, so the largest number is 2,147,483,647
    • May 17 2011 | 10:16 pm
      Just wanted to say....
      This is awesome love the thread
      Fly Pro.