Answers for "python random with probability"

0

python generate random string with lenght

import random
import string

def randStr(chars = string.ascii_uppercase + string.digits, N=10):
	return ''.join(random.choice(chars) for _ in range(N))

# default length(=10) random string
print(randStr())
# random string of length 7
print(randStr(N=7)) 
# random string with characters picked from ascii_lowercase
print(randStr(chars=string.ascii_lowercase))
# random string with characters picked from 'abcdef123456'
print(randStr(chars='abcdef123456'))
Posted by: Guest on January-24-2021
0

random with probability python

import random

data = [1, 2, 3, 4, 5, 6]
probability = [0.3, 0.3, 0.1, 0.1, 0.1, 0.1]
 
random.choices(data, probability)
Posted by: Guest on May-04-2021
0

python random how to get trng

>>> unique_strings(k=4, ntokens=5)
{'AsMk', 'Cvmi', 'GIxv', 'HGsZ', 'eurU'}

>>> unique_strings(5, 4, string.printable)
{"'O*1!", '9Ien%', 'W=m7<', 'mUD|z'}
Posted by: Guest on December-27-2020

Code answers related to "python random with probability"

Python Answers by Framework

Browse Popular Code Answers by Language