I need to random some elements from an array. I’m doing that by randomizing the index $array[int(rand(100))]. I want some of the elements to appear more often. How do I do it?
I thought of a stupid solution of having those elements duplicated several times in the array, but I’m sure you guys can do better.
this sub’ gets an array of element and weight -A(10)B(30)C(5)-and random one of the elements according the weights.
sub we_rand {
}
you call the sub’ like this:
my $rand=we_rand(A(10)B(30)C(5)D(17));
-#$rand=B