Message Boards Message Boards

0
|
5329 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Weight RandomSample with multiple lists

Posted 9 years ago
RandomSample[{0.5,0.5}->{2,4},1]

commands Mathematica to select either 2 or 4 with a 50:50 chance of either number. How can I use this if I have multiple lists, like this:

RandomSample[{{0.5,0.5},{0.4,0.6}}->{{2,4},{3,5}},1] except this command returns an error

I don't want to combine the lists because I want to select one number from each list with separate probabilities.

Thanks for the help!

POSTED BY: Justin Walsh
2 Replies

Could use MapThread.

MapThread[
 RandomSample[Rule[##], 1] &, {{{0.5, 0.5}, {0.4, 0.6}}, {{2, 4}, {3, 5}}}]
POSTED BY: Daniel Lichtblau
Posted 9 years ago

Probably

RandomSample[{0.5, 0.5} -> {2, 4}, 1]~Join~RandomSample[{0.4, 0.6} -> {3, 5}, 1]
POSTED BY: Karsten 7.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract