Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use random in python

import random
print(random.randint(3, 7)) #Prints a random number between 3 and 7
array = [cars, bananas, jet]
print(random.choice(array)) #Prints one of the values in the array at random
Comment

random number generator in python

import random

a = random.randint(0,10)
print(random.randint(0,a))
Comment

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 return the sum of two numbers python 
Python :: python string does not contain 
Python :: python int to ascii string 
Python :: python iterator 
Python :: python list extend 
Python :: python list clear vs del 
Python :: iloc[:,0:-1] 
Python :: type of tuple in python 
Python :: python string after character 
Python :: import a module in python 
Python :: django filter values with e and operator 
Python :: csv to excel python 
Python :: search method in python 
Python :: pandas sum 
Python :: flask page 
Python :: how do variables work in python 
Python :: python syntaxerror: unexpected character after line continuation character 
Python :: Python Map Function Syntax 
Python :: Sys Gets os name ,which u using 
Python :: python click activator 
Python :: spotify recommendations 
Python :: django model make the field caseinsensitive 
Python :: Missing Data Plotly Express px.data 
Python :: sum of multiples of 5 from 1 to 100 
Python :: Forth step - Creating new app 
Python :: matplotlib smooth loss curves 
Python :: how to find 6,6,77,8 in python 
Python :: numpy create array with infinities 
Python :: Iterate through string in chunks in python 
Python :: concatenate the next row to the previous row pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =