Random that doesn't repeat?

I’m working on my granular method, which is long and complicated, but I’m running into what ought to be a simple problem.
I’m running a series of nested loops, trying to randomly calculate the starting point for a grain. But I find that the rrand function keeps returning the same values, so the grains follow a repeating pattern from loop to loop. In other words, it’s generating the same values over and over again.
I’ve tried reinitializing the seed, using use_random_seed = Time.now.to_i % 65536, but I’m still getting the repetition.
What’s the secret to having repeated iterations come up with different random values? This ought to be easy and obvious, but I’m stuck in my thinking.
Thanks!

Hi @HarryLeBlanc,

could you share your code so we can see what you’re doing? If you can make it as simple as possible whilst still demonstrating your issue that would be really helpful :slight_smile:

I think I solved my problem. I generated an array of random seeds, and ticked through them with each choice, which broke up the repetition.
I found that, if I generated subsequent seeds based on Time.now, that the same pattern would show up, but be shifted by one or two new random entries at the beginning. As I’m working with super-tiny time slices, this sounded repetitive. But shuffling the keys, generated using rrand(0, 65536) did the trick.

Here are the code fragments I used:


    seeds = []
    256.times do  
      seeds << rrand(0, 65536)
    end #256times
#...

         thisnote = notes.choose(seeds.tick(:grains_seeds))
 
1 Like