Random

seed()

The seed() method is used to initialize the random number generator.
The random number generator needs a number to start with (a seed value), to be able to generate a random number.
By default the random number generator uses the current system time.

# python current system time

Date d = new Date();
CharSequence s  = DateFormat.format("EEEE, MMMM d, yyyy ", d.getTime());

DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("GMT+05:30"));

df.format(new Date(System.currentTimeMillis());

Use the seed() method to customize the start number of the random number generator.
Note: If you use the same seed value twice you will get the same random number twice. See example below

random.seed(a, version)
usagedesc
aOptional. The seed value needed to generate a random number. If it is an integer it is used directly, if not it has to be converted into an integer. Default value is None, and if None, the generator uses the current system time.
versionAn integer specifying how to convert the a parameter into a integer. Default value is 2

getstate()

setstate()

getrandbits()

The getrandbits() method returns an integer in the specified size (in bits).

randrange()

random.randrange(start, stop, step)

randint()

choice()

random.choice("syahrul"), random.choice("aa", "bb", "cc")

choices()

The choices() method returns a list with the randomly selected element from the specified sequence.
You can weigh the possibility of each result with the weights parameter or the cum_weights parameter.
The sequence can be a string, a range, a list, a tuple or any other kind of sequence.

random.choices(sequence, weights=None, cum_weights=None, k=1)
UsageDesc
sequenceRequired. A sequence like a list, a tuple, a range of numbers etc.
weightsOptional. A list were you can weigh the possibility for each value. Default None
cum_weightsOptional. A list were you can weigh the possibility for each value, only this time the possibility is accumulated. Example: normal weights list: [2, 1, 1] is the same as this cum_weights list; [2, 3, 4]. Default None
kOptional. An integer defining the length of the returned list

Return a list with 14 items. The list should contain a randomly selection of the values from a specified list, and there should be 10 times higher possibility to select "apple" than the other two:

import random
mylist = ["apple", "banana", "cherry"]
print(random.choices(mylist, weights = [10, 1, 1], k = 14)) 

shuffle()

random.shuffle(sequence, function) 

function : Optional. The name of a function that returns a number between 0.0 and 1.0. If not specified, the function random() will be used

sample() Returns a given sample of a sequence

random.sample(sequence, k) 

random()

Returns a random float number between 0 and 1

uniform()

Returns a random float number between two given parameters

triangular()

Returns a random float number between two given parameters, you can also set a mode parameter to specify the midpoint between the two other parameters

betavariate()

Returns a random float number between 0 and 1 based on the Beta distribution (used in statistics)

expovariate()

Returns a random float number based on the Exponential distribution (used in statistics)

gammavariate()

Returns a random float number based on the Gamma distribution (used in statistics)

gauss()

Returns a random float number based on the Gaussian distribution (used in probability theories)

lognormvariate()

Returns a random float number based on a log-normal distribution (used in probability theories)

normalvariate()

Returns a random float number based on the normal distribution (used in probability theories)

vonmisesvariate()

Returns a random float number based on the von Mises distribution (used in directional statistics)

paretovariate()

Returns a random float number based on the Pareto distribution (used in probability theories)

weibullvariate()

Returns a random float number based on the Weibull distribution (used in statistics)

Random Cracker

import random, time
from randcrack import RandCrack

random.seed(time.time())

rc = RandCrack()

for i in range(624):
	rc.submit(random.getrandbits(32))
	# Could be filled with random.randint(0,4294967294) or random.randrange(0,4294967294)

print("Random result: {}\nCracker result: {}".format(random.randrange(0, 4294967295), rc.predict_randrange(0, 4294967295)))