Better random number generation

TobyAM's icon

Hi, I'm trying to create a plugin that has a random seed on each new instance.
As of now, all "random" objects on all instances of a plugin share the same seed on load.
I need each instance to start with a unique(ish) seed, and I'm failing to see a way to do that.
Any thoughts?

Peter Ostry's icon

[random] accepts a seed argument.
[set seed 0] should work for you. See help file.

TobyAM's icon

The problem is that on a project load all instances of the plugin are loaded at the same time, and since the seed 0 works based on the system time, all instances have the same random numbers generated.

ecuk's icon

Use a single zero-seeded random to generate a sequence of numbers to use as seeds for the other random objects??

TobyAM's icon

They're all separate instances of a plugin

nouserid's icon

Hey, how's this?

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

TobyAM's icon

Thanks Nouserid, this is an interesting example I'll try incorporating!
Would you mind explaining the concept here?

nouserid's icon

You're welcome :) The argument #0 in the loadmess object will generate a unique number for each instance of an abstraction or bpatcher. It works with lots of other objects too!

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

TobyAM's icon

This actually doesn't work in RNBO; it's an invalid argument.

Rodrigo's icon

I use this for all my random number generation (seems to work fine in RNBO too).

[expr (random(-32768, 32767) + 32768) / 65536.]