Search code examples
randomnumbersgenerated

How to make two different code generate random numbers but they are different?


Let's say I have a code following under

a = 4
b = random.sample(range(1,14), (a))

Now if I print this, this would give me random 4 numbers in range 1~13 and let's say it is [3, 7, 1, 11]

However, I want to add another line under that code which will generate additional 3 different numbers in range 1~13 that the first code did not generate. e.g [4, 9, 13]

How should I do it? Thanks in advance.


Solution

  • I think you want something like this:

    a = 4
    b = random.sample(range(1,14), (a))
    c = random.sample([x for x in range(1,14) if x not in b], (a))