How can I get weighted random selections from an array in Perl?
Posted
by Chaggster
on Stack Overflow
See other posts from Stack Overflow
or by Chaggster
Published on 2009-12-31T07:04:39Z
Indexed on
2010/03/14
6:45 UTC
Read the original article
Hit count: 157
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.
© Stack Overflow or respective owner