Created
October 1, 2017 21:41
-
-
Save kai5263499/a582b173cdd7da2759d1c9d6bd24aa15 to your computer and use it in GitHub Desktop.
Mix lists with a given ratio
This file contains 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
# inspired by https://stackoverflow.com/questions/10644925/randomly-interleave-2-arrays-in-python | |
def mix_with_ratio(a, b, ratio): | |
c = [] | |
while a and b: | |
which_list = random.random() | |
if which_list < ratio: | |
c.append(a.pop(0)) | |
else: | |
c.append(b.pop(0)) | |
return c | |
# 10% chance of mixing b into a | |
mix_with_ratio(['a' for x in range(10)], ['b' for x in range(10)], 0.90) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment