How to create 10,000 random coordinates in python?

Viewed 12437

Hello I've been set a project where I have to generate 10,000 random coordinates (x,y), using the random module in python and then output them all. The coordinates HAVE to be decimal numbers between 0 and 2. I've had a look around on the internet but I can't seem to find anything that is helping me. Can anyone on here help me? Thank you.

2 Answers

Or use numpy:

import numpy as np

coords = np.random.rand(10000, 2) * 2

Use the random module within a list comprehension to generate a list of random coordinate tuples:

import random

coords = [(random.random()*2.0, random.random()*2.0) for _ in range(10000)]

This will give you 10,000 tuples (x, y), where x and y are random floating point numbers greater than or equal to 0 and less than 2.

Related