I've spent the last few hours trying to figure how to do something relatively simple- i'd like to write a python script that returns a number of strings from a predefined alphabet using certain weights. So for example
strings = 3
length= 4
alphabet = list('QWER')
weights=[0.0, 0.0, 0.0, 1.0]
this would return
RRRR RRRR RRRR
or another example
strings = 2
length= 3
alphabet = list('ABC')
weights=[0.3,0.3,0.3]
This would return
CBA ABC CAA
I've tried playing around with a number of example codes and this is the closest i've come-
import random
import numpy as np
LENGTH = 3
NO_CODES = 100
alphabet = list('ABCD')
weights=[0.0, 0.0, 0.0, 1.0]
np_alphabet = np.array(alphabet, dtype="|U1")
np_codes = np.random.choice(np_alphabet, [NO_CODES, LENGTH])
codes = ["".join(np_codes[i]) for i in range(len(np_codes))]
print(codes)
However, i know i'm not using the weight function correctly. If anyone can tell me what i'm doing wrong or suggest a better way to do it, that would be appreciated. As i'm sure you can tell i don't really know what i'm doing, so any advice would be useful.