Last active
December 10, 2015 22:28
-
-
Save salimfadhley/4502352 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Id: "$Id$" | |
Description: | |
Test: | |
''' | |
""" | |
Given a list of probabilities (floats), and a list of values (anything), write a function/class/whatever: | |
go(probs, values) | |
that produces values with the given probabilities. | |
For example, you'd expect that using: | |
go([0.3, 0.7], ['hello', 'world']) | |
100 times would give (roughly, but probably not exactly) 30 'hello's and 70 'world's, in a jumbled order. It's basically a random value selector. | |
Bear in mind that you don't know in advance how many random values the are required. We also do not know how may values the function may need to select from. | |
There are many ways to write this, many interfaces -- go could be a function, a class, whatever you want. | |
Try to do it in the most Pythonic way possible, and write some unit tests. | |
""" | |
import random | |
import unittest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment