Hi folks, random functions are very useful in more cases that you think. Today I will give you some tips about randomizing python scripts with the random module. This simple module has some interesting functions to see deeper:
- random (): Generate a float number in range 0.0 <= x < 1.0.
- uniform (a, b): Generate a float number in range a<= x < b.
- randint (a, b): Generate an integer number in range a <= x <= b.
- randrange (a, b, step): Select an integer number in a given range. This range is equal to built-in range (a, b, step).
And now, functions over sequences:
- choice (sequence): Return an element of the sequence.
- shuffle (sequence): Shuffle element of sequence in-place (the same sequence reference).
- sample (sequence, n): Return a new sequence of n length with elements from sequence.
- populate (sequence, n): The same as sample, but elements of new sequence don’t have repetitions.
For more information about random module, visit this.
This is all for now. Stay tuned for more interesting code snippets. Comments welcomed.