How to generate a string token using four of this items random

0 votes
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 by Rajiv
• 8,880 points
117 views

1 answer to this question.

0 votes

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 Gitika
• 65,930 points

Related Questions In Python

+1 vote
2 answers

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[0]              for i in range(len(s)):                     if ...READ MORE

answered Oct 28, 2020 in Python by Anurag
7,983 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,440 points
455 views
–1 vote
2 answers

How to find the size of a string in Python?

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

answered Mar 29, 2019 in Python by rajesh
• 1,230 points
528 views
0 votes
1 answer

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

answered Oct 31, 2018 in Python by Anirudh
• 2,080 points

edited Dec 14, 2018 by Anirudh 306 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

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

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,256 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

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

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,688 views
0 votes
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,000 points
49,677 views
0 votes
1 answer

how to run test cases of different modules with same marker at a time using pytest

Hey,@Nikitha, Suppose you have multiple files say test_sample1.py, test_sample2.py. To ...READ MORE

answered Apr 28, 2020 in Python by Gitika
• 65,930 points
137 views