How to generate numbers from the Fibonacci Sequence?

brookedavis101's icon

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?

thanks

Chris Muir's icon

I would put numbers from the Fibonacci sequence in a coll or table, and select them randomly.

ehdyn's icon

Two immortal rabbits + single malt scotch and just let nature take its course

brookedavis101's icon

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

o s's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Please examine carefully the used objects by alt-clicking them (open helpfile) to see how they work...
hth o

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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:
https://cycling74.com/forums/common-max-arcana

Roman Thilenius's icon

2115.110.fibonacci.zip
zip
o s's icon

@ Chris Muir: thanks for your improvement. I was not aware of the funnel and the listfunnel objects until today...

ole

brookedavis101's icon

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?

brendan mccloskey's icon

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.

Brendan

Roman Thilenius's icon

what he said ... plus some fixes.

Orkester's icon

I became interested in 'sacred geometry' through music, and interested in general math through geometry, and programming through general math...so 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.

Max Patch
Copy patch and select New From Clipboard in Max.

Est voila!

Roth's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's how I generate random Fibonacci numbers in my patches:

Orkester's icon

Ha!

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.

laonikoss's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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):

Roman Thilenius's icon

a 6th version anyone?

btw, finbonacci numbers are SO useless for music. ^^

Chris Muir's icon

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)

Orkester's icon

@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.

Justin G's icon

btw, finbonacci numbers are SO useless for music.

yeah so are major and minor scales. and chords.

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

It took a little digging, but I found my bucket-based version:

Orkester's icon

How does it work?

Roman Thilenius's icon

yeah, but my bucket version is greener than yours.

mzed's icon

There's a generator for Lucas Sequences in the CNMAT MMJ Depot, downloadable here: http://cnmat.berkeley.edu/downloads

Fibonacci numbers are a subset of that.

mz

mr_mapes's icon

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....

Chris Muir's icon

Max uses a signed 32 bit word, so the largest number is 2,147,483,647

DaniCW's icon

Just wanted to say....

This is awesome love the thread

Fly Pro.