Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

random list generator

"""
Generation of non-unique 1d_lst
- Function takes in 3 parameters (that has been defaulted)
- If you are looking to generate unique lsts...
  ...you might want to use random.sample() on a lst of numbers...
  ...such as list(_ for _ in range(10))
"""

from random import randint
def nu_rand1d(r = 10, low = 11, high = 99): # r is range, nu means non-unique
    return [randint(low, high) for num in range(r)]

"""
- Note that randint is inclusive
  e.g. If x = randint(10, 100), 10 <= x <= 100
  
- If you prefer, you can use randrange which is exclusive like range()
  e.g. If x = randrange(10, 100),  10 <= x <= 99
"""
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #random #list #generator
ADD COMMENT
Topic
Name
4+8 =