Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python random number generator no duplicates

import random

def random_sample(count, start, stop, step=1):
    def gen_random():
        while True:
            yield random.randrange(start, stop, step)

    def gen_n_unique(source, n):
        seen = set()
        seenadd = seen.add
        for i in (i for i in source() if i not in seen and not seenadd(i)):
            yield i
            if len(seen) == n:
                break

    return [i for i in gen_n_unique(gen_random,
                                    min(count, int(abs(stop - start) / abs(step))))]
Comment

python random number generator no duplicates

python -c "import random; print(sorted(set([random.randint(6,49) for i in range(7)]))[:6])"
Comment

How do I create a list of random numbers with duplicate python

import random
dupl_list = [random.randint(1,50) for x in range(20)]
print (dupl_list)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas divide multiple columns by one column 
Python :: python remove one character from a string 
Python :: re.match python 
Python :: python log file 
Python :: series astype 
Python :: python sort a 2d array by custom function 
Python :: how to take out every even number from a list in python 
Python :: tensorflow inst for python 3.6 
Python :: lists to dictionary python 
Python :: python beautifulsoup xpath 
Python :: date time shit pandas 
Python :: calculate mean of column pandas 
Python :: upload file to aws 
Python :: python byte like to string 
Python :: class indexing 
Python :: python zip folder and subfolders 
Python :: matplotlib axis labels 
Python :: find the last point of line geopanda 
Python :: liste compréhension python 
Python :: super in django manager 
Python :: a int and float. python 
Python :: django channel 
Python :: Your WhiteNoise configuration is incompatible with WhiteNoise v4.0 
Python :: django update field after save 
Python :: how to convert string to integer in python 
Python :: python how to drop columns from dataframe 
Python :: how to convert response to beautifulsoup object 
Python :: post list python 
Python :: python captcha bypass 
Python :: obtain files python 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =