Weighted Pick - Array Extension

30 views
Skip to first unread message

taelor

unread,
Feb 12, 2009, 11:18:09 AM2/12/09
to Ruby Faker
Gents,

Tell me what you think about this extension to the array class for
faker.

I have been having to come up with alot of fake data, and I wanted to
randomly pick from an array, but pick certain things more than others.
So came up with the idea of a weighted_pick from an array.

http://pastie.org/387157

basically, the idea is to give the first index in the array the
highest chance of getting picked, and the last place getting the
lowest. the first index gets (roughly) a 50% chance, the second gets a
25%, the third a 12.5% and so on.

I also have been working on a Faker::Financial addition, but its not
quite ready to post yet.
Reply all
Reply to author
Forward
0 new messages