Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python random geneator

#import 'random' library
import random 
#print infinitely and randomly
while 1:
	rand = random.randint(1,10)
	print(rand)
Comment

random generator python

"""Generation of non-unique 1d_lst and 2d_lst
- Function takes in a list of info about the non-unique list

- You can also import randint from random. 
  - Note that randint is inclusive and randrange is exclusive.
  
- If you are looking to generate unique lsts...
  ...you might want to use random.sample() on a lst of numbers.
"""

from random import randrange

dft = [10, 10, 100, 10] # dft = default (range, low, high, row)

def rand_1d(info = dft[:-1]):
    r, low, high = info # r: range
    return [randrange(low, high) for num in range(r)]

def rand_2d(info = dft):
    *info_1d, rows = info
    return [rand_1d(info_1d) for i in range(rows)]

## Test
randlst_gen = {
    "rand_1d": rand_1d,
    "rand_2d": rand_2d
}
r1, r2 = randlst_gen.values() # get the functions

# #function 1
# print("rand_1d --------------------------------------------------")
# print(f"default: {r1()}")
# print(f"rand: {r1([5, 3, 234])}")
# print()
# # function 2
# print("rand_2d --------------------------------------------------")
# print("default:")
# for row in r2(): 
#     print(row)
# print()
# print("rand:")
# for row in r2([8, 11, 30, 5]): 
#     print(row)
Comment

PREVIOUS NEXT
Code Example
Python :: python roman to integer 
Python :: sklearn random forest regressor 
Python :: concat dataFrame without index reset 
Python :: eigenvectors python 
Python :: how to take screenshots with selenium webdriver python 
Python :: How do I set Conda to activate the base environment by default? 
Python :: pandas columns starting with 
Python :: python print how long it takes to run 
Python :: python loop through directory 
Python :: generate python date list 
Python :: how to make a blank window open up in python 
Python :: python print float in scientific notation 
Python :: prettytable python 
Python :: python get image dimensions 
Python :: correlation matrix python 
Python :: python turtle line thickness 
Python :: python opencv write text on image 
Python :: discord.py set activity 
Python :: django admin prefetch_related 
Python :: list to json python 
Python :: dataframe select entries that are in a list 
Python :: openpyxl read excel 
Python :: pandas append dictionary to dataframe 
Python :: how to set chrome options python selenium for a folder 
Python :: python system arguments 
Python :: get length of csv file with python 
Python :: python setup.py bdist_wheel did not run successfully 
Python :: python convert file into list 
Python :: python object to json file 
Python :: how to get variable from setings django 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =