Help with probability spawning

Hi

I’m spawning different colors based on random function:

local color = math.random(1,L.Stats.maxColors)  
  
if color == 1 then color = "red"   
elseif color ==2 then color = "blue"  
elseif color ==3 then color = "green"  
end  

once the color is generated, the object with chosen color is spawned.

Problem is, that sometimes, one color is generated for about 5 times in a row. I’m trying to find a procedure that will decrease the probability of particular color once it is spawned. I think the correct way is to add a counter for each color to know, how many times it was spawned, but what’s next?

Does anyone has any ideas how to deal with that?

Thanks in advance [import]uid: 181861 topic_id: 33535 reply_id: 333535[/import]

Infinityx,

So what are you trying to achieve? get the number of f spawned objects to be even in colour?

ie if you are spawning 100 objects you want 33 to be red? 33 to be blue? 33 to be green? [import]uid: 67619 topic_id: 33535 reply_id: 133288[/import]

The problem has to do with over a short run, you can flip a coin 10 times and get 10 heads. Its the way random works. Over the long haul it will average out but it’s possible to get runs of the same number.

You could so something like if you show green, the next one is random (red, blue), then the next one is random blue, green. I don’t have a code snippit to do this, but it would solve the short run same color problem and give you the illusion of random.
[import]uid: 199310 topic_id: 33535 reply_id: 133318[/import]

You could so something like if you show green, the next one is random (red, blue), then the next one is random blue, green. I don’t have a code snippit to do this, but it would solve the short run same color problem and give you the illusion of random.

I think I’ve solved that with this idea, thanks :slight_smile: [import]uid: 181861 topic_id: 33535 reply_id: 133338[/import]

Infinityx,

So what are you trying to achieve? get the number of f spawned objects to be even in colour?

ie if you are spawning 100 objects you want 33 to be red? 33 to be blue? 33 to be green? [import]uid: 67619 topic_id: 33535 reply_id: 133288[/import]

The problem has to do with over a short run, you can flip a coin 10 times and get 10 heads. Its the way random works. Over the long haul it will average out but it’s possible to get runs of the same number.

You could so something like if you show green, the next one is random (red, blue), then the next one is random blue, green. I don’t have a code snippit to do this, but it would solve the short run same color problem and give you the illusion of random.
[import]uid: 199310 topic_id: 33535 reply_id: 133318[/import]

You could so something like if you show green, the next one is random (red, blue), then the next one is random blue, green. I don’t have a code snippit to do this, but it would solve the short run same color problem and give you the illusion of random.

I think I’ve solved that with this idea, thanks :slight_smile: [import]uid: 181861 topic_id: 33535 reply_id: 133338[/import]