Reputation: 8995
Using pybricks-micropython
Running this command to get a random port number, works under CPython.
import random
port = random.randint(50000,50999)
produces a number, only it is hardly random it is the same number each time I run the script. I am guessing MicroPython needs something more perhaps?
What am I missing?
Upvotes: 1
Views: 709
Reputation: 8995
John,
I looked up seed with random and used epoch time. Solved.
millis = int(round(time.time())
random.seed(millis)
port = random.randint(50000,50999)
Ok almost certainly produces a random you could predict, but hey this isn't for the lottery or anything, its for a port number :)
Thanks you, you seeded that answer, forgive the pun.
Upvotes: 1