Reputation: 59
Recently been discovering the numpy
package in Python. Is anyone familar with random dataset generation? For floats I use
FOOBAR = (np.random.normal(mean_desired,stdev,N-size_target of_population), dim_of_array)
It works pretty well but not sure how to setup a random string generator for lets say a a set of strings like these: "GK", "A", "M", D" and populate the dataset with these randomly.
Upvotes: 1
Views: 361
Reputation: 24181
You can use random.choices
to sample with replacement:
import random
pop = ["GK", "A", "M", "D"]
random_sample = random.choices(pop, k=10)
random_sample
>>> ['D', 'A', 'A', 'GK', 'M', 'D', 'M', 'A', 'GK', 'GK']
Upvotes: 1