Advertisement
Guest User

MCVE

a guest
Aug 5th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. from random import randint
  2.  
  3. # List of indices corresponding to streambits that will be changed
  4. chosen_streambits = []
  5.  
  6. # Number of letters that will be replaced with a "T"
  7. num_t = 5
  8.  
  9. # Sample stream
  10. 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"]]
  11.  
  12. # This process will be done num_t times
  13. for _ in range(num_t):
  14.     # Select a random streambit
  15.     rand_streambit = randint(0, len(stream)-1)
  16.     # List of ranges, each centered on a previously chosen "T"
  17.     plus_or_minus_two_off = [range(x-2, x+3) for x in chosen_streambits]
  18.  
  19.     while True:
  20.         # Check if rand_streambit is within the ranges centered around other "T"s
  21.         if rand_streambit not in plus_or_minus_two_off:
  22.             # If it's not, add it to chosen_streambits and break
  23.             chosen_streambits.append(rand_streambit)
  24.             break
  25.         else:
  26.             # If it is, resample and repeat the loop
  27.             rand_streambit = randint(0, len(stream)-1)
  28.  
  29. # Go through the chosen streambits (num_t long) and assign a random letter in them to "T"
  30. for chosen_one in chosen_streambits:
  31.     rand_letter = randint(0, len(stream[chosen_one]) - 1)
  32.     stream[chosen_one][rand_letter] = "T"
  33.  
  34. # We would expect to see stream again, but with T's randomly scattered
  35. #   through the list and never within two streambits of each other
  36. print(stream)
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement