I want to use
np.random.randint(4, size=2)
to create a pair of different random numbers from 0 to 3. The problem is that it sometimes gives (0,0), (3,3), etc. Is there a way to make numbers be different?
you can use random.choice:
random.choice
import numpy as np np.random.choice(a=np.arange(4), size=2, replace=False)
or, more concise (as Nuageux noted ):
np.random.choice(a=4, size=2, replace=False)
for people who do not want to use numpy
numpy
import random left_end = 0 right_end = 3 length = 2 random.sample(range(left_end, right_end), k=length)
you can also wrap it in tupleif you need to, as it random.samplereturns listan object
tuple
random.sample
list
Source: https://habr.com/ru/post/1677153/More articles:How to use javascript variable as text? - javascriptПреобразование строки из текстового файла в целочисленный массив - c#as an example of Eq without output - haskellInvoke-WebRequest, GET с параметрами выбрасывает исключение - c#Difference between HDF and Apache NiFi - hortonworks-data-platformWebpack 2 Asynchronous Code Conversion CDN - webpackAndroid: expression for data binding using enum transformation - androidJenkins Pipeline and a huge number of parallel steps - jenkinsRedux appropriations require cancellation - reactjsАгрегация данных. Таблица с суммой, длиной и grep - grepAll Articles