Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- # List of indices corresponding to streambits that will be changed
- chosen_streambits = []
- # Number of letters that will be replaced with a "T"
- num_t = 5
- # Sample stream
- stream = [["A", "N"], ["S", "U"], ["E", "R"], ["V", "J"], ["A", "N"], ["S", "U"], ["E", "R"], ["V", "J"], ["A", "N"], ["S", "U"], ["E", "R"], ["V", "J"]]
- # This process will be done num_t times
- for _ in range(num_t):
- # Select a random streambit
- rand_streambit = randint(0, len(stream)-1)
- # List of ranges, each centered on a previously chosen "T"
- plus_or_minus_two_off = [range(x-2, x+3) for x in chosen_streambits]
- while True:
- # Check if rand_streambit is within the ranges centered around other "T"s
- if rand_streambit not in plus_or_minus_two_off:
- # If it's not, add it to chosen_streambits and break
- chosen_streambits.append(rand_streambit)
- break
- else:
- # If it is, resample and repeat the loop
- rand_streambit = randint(0, len(stream)-1)
- # Go through the chosen streambits (num_t long) and assign a random letter in them to "T"
- for chosen_one in chosen_streambits:
- rand_letter = randint(0, len(stream[chosen_one]) - 1)
- stream[chosen_one][rand_letter] = "T"
- # We would expect to see stream again, but with T's randomly scattered
- # through the list and never within two streambits of each other
- print(stream)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement