1

So basically I have an array and I want to randomly put 100 objects inside it, each object also have a chance property like 5 for 5% or 10 for 10%. My question is, does anyone have any idea for a smart way to do this?

I tried something like picking a random number from 1-100 inside a for loop and with multiple if statements just add an object so for example if the number is between five and zero then I'll put the 5% probability object in the array and repeat. This solution is obviously not very elegant and efficient though does anyone have any ideas for how I can accomplish this?

Tay Baye
  • 29
  • 1

0 Answers0