Use the random
module: http://docs.python.org/library/random.html
import random
random.sample(set([1, 2, 3, 4, 5, 6]), 2)
This samples the two values without replacement (so the two values are different).
More Related Contents:
- How can I randomly select an item from a list?
- How do I create a list of random numbers without duplicates?
- Generate random integers between 0 and 9
- Generate ‘n’ unique random numbers within a range [duplicate]
- Pick N distinct items at random from sequence of unknown length, in only one iteration
- Consistently create same random numpy array
- How to generate a random number with a specific amount of digits?
- Generate a random letter in Python
- Generating random dates within a given range in pandas
- Python random sample with a generator / iterable / iterator
- Read a small random sample from a big CSV file into a Python data frame
- Random row selection in Pandas dataframe
- How to generate random numbers that are different? [duplicate]
- Sampling uniformly distributed random points inside a spherical volume
- How to generate random strings in Python?
- Binary random array with a specific proportion of ones?
- Difference between np.random.seed() and np.random.RandomState()
- Should I use `random.seed` or `numpy.random.seed` to control random number generation in `scikit-learn`?
- Create random list of integers in Python
- Python: Random selection per group
- Generating Discrete random variables with specified weights using SciPy or NumPy
- How to hash a string into 8 digits?
- Python – shuffle only some elements of a list
- Random non overlapping circles(with circle number controlled) in python and pygame
- Getting random row through SQLAlchemy
- TensorFlow: Non-repeatable results
- Generate random locations within a triangular domain
- Can I generate authentic random number with python?
- Generate random array of floats between a range
- Best way to choose a random file from a directory