Y
Y
Yakovlev Daniil2021-10-28 07:41:59
Python
Yakovlev Daniil, 2021-10-28 07:41:59

How can I make random pick a sequence of three characters, but without repeating?

how to make it randomly give us all possible sequences of numbers 0-9, the entire English alphabet and "_" and not repeat

again, so that randomly gives us all sequences of 3 characters long

example:
s83
_s2
as5
an_
_as2
moi

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2021-10-28
@Kil0Gramm

Secondly, the concept of "non-recurring" excludes the concept of "random". By the very fact of tracking the repetition and controlling it, you contribute a share of the order.
In this case, it seems to me, "shuffle", shuffle is applicable.
Take numbers from 0 to 9 and shuffle random.shuffle()

import random

mylist = ["apple", "banana", "cherry"]
random.shuffle(mylist)

print(mylist)

Then you can take the first three from the shuffled list, and here you have 3 non-repeating random ones.
As for the third question, I recommend trying it yourself, then come with options for your attempts to solve a new question, and we will discuss. This is not the place to get solutions without difficulty.

A
Andrey Dugin, 2021-10-28
@adugin

from random import sample
from itertools import permutations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question