Hi

("35" + "34" + "37" + "36" + "31" + "30" + "33" + "32" + "3d" + "3c")

I like to generate a string token using four of this items random, how can I do it?

example 353d3136 Nov 15, 2020 in Python 117 views

## 1 answer to this question.

One approach just generates random integers up to the length of this list and then take the generated random integers as the index and form the token.

r = random.choices(["35" , "34" , "37" , "36" , "31" , "30" , "33" , "32" , "3d" , "3c"] ,k=4)
"".join(r)

OR

code = random.choices(["35" , "34" , "37" , "36" , "31" , "30" , "33" , "32" , "3d" , "3c"], k=4)
X ="".join(code)
return X

This might work answered Nov 15, 2020 by
• 65,930 points

+1 vote

## How to print first character of each word in upper case of a string in Python

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s              for i in range(len(s)):                     if ...READ MORE

–1 vote

## How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

## How do I generate some random numbers with a distribution using Python?

scipy.stats.rv_discrete is what you ned IMHO. You can supply ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE