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 :: how to set variable to null in python 
Python :: python loop go back to start 
Python :: pandas groupby mean round 
Python :: python substring in string 
Python :: python bar plot groupby 
Python :: sort an array python 
Python :: python factorial 
Python :: how to run python module every 10 sec 
Python :: python re compile 
Python :: How are iloc and loc different? 
Python :: python array append 
Python :: how to set variable in flask 
Python :: create pytorch zeros 
Python :: tuple plot python 
Python :: python check if website is reachable 
Python :: python count values in list 
Python :: display array of odd rows and even columns in numpy 
Python :: print flush python 
Python :: backtracking python 
Python :: process rows of dataframe in parallel 
Python :: python make file executable 
Python :: matplotlib display graph on jupyter notebook 
Python :: sqlalchemy create engine MySQL 
Python :: how to search in django 
Python :: python align label left 
Python :: delay print in python 
Python :: set xlim histogram python 
Python :: turn python script into exe 
Python :: open csv from url python 
Python :: how to unlist a list in python 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =