0

I want to generate 18000 numbers (integers) between 36499 and 130064, but two times, and insert them in two different lists. I want the numbers in each list to be unique, that is, different from each other in the list, and different from every number in the other list. So I've decided to use the random.sample method and so far i have

import random
random.seed(9000)

a = random.sample(range(36499, 130064), 18000)

All good so far. However if I do the same for, say, a list called "b", some numbers will exist in list "a" as well. Is this any way you guys can think of to generate 18000 numbers different from the ones already generated? Thanks

0

2 Answers 2

3

you could generate 36000 random numbers instead of 18000, and then produce list A and list B from that.

Sign up to request clarification or add additional context in comments.

3 Comments

oh my god, you are right. Thanks a lot i feel bad for not thinking this :P
c = random.sample(range(36499, 130064), 36000); a = c[:18000]; b = c[18000:] ?
@JohanC I'd say too ordinary, a, b = c[::2], c[1::2] is slightly more interesting.
1

You could work with sets:

import random

random.seed(9000)
numbers = range(36499, 130064)
a = random.sample(numbers, 18000)
b = random.sample(set(numbers) - set(a), 18000)

2 Comments

Thanks a lot for the answer! I know what set() but to be honest its the first time i encounter something of the form set(a) - set(b). I'll have to run some tests to see what it does.
Great! Thanks a lot :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.