Python Forum

Full Version: find random numbers that are = to the first 2 number of a list.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Dean you are asking a very good question.
In the first case it return attempt 3722 : [1, 2, 3, 12]
In the second approach: [1, 2, 55, 86]

If i increase the number in my start_list and i increase to for _ in range(12) it will take longer to find my condition.
I am using programiz terminal online.
When it computes to find the answer does it use my pc or programiz server?

It could take days before it find the serie that match multiple conditions. Is there a way to speed up the process?

TY
Why are you trying to find a series that matches? What is the pupose behind your code?
looking for reccuring mathematical pattern.
Is order important?
Yes it is. Its a process of elimination to lower the number of possibilities returned using more numbers we know. The more i will add numbers the greater the compute power it needs.

If i am not mistaken we have 1/94 109 400 of getting 4 numbers on 100 or 100!/94!. Of course 4! 24 so 3 921 225

Strangely the computer should go through all those possibilities but the range (1, 140000000) is greater than 3 921 225, so i suppose more series than needed to find numbers that match the conditions.
The computer will generate all the random series of numbers with 4 numbers and it will stop when the first 2 numbers will be 1 and 2 or 3 and 6 or any specific numbers you have in mind.
At a second per serie of numbers to check it could take up to 45 days before i get a return.
Frankly, it's quite unclear what exactly you try to do.
i.e. if you want to generate a random list of 6, that starts with (1, 2) or (3, 6), then I would randomly choose one of the two, then generate 4 more random numbers and combine the two into list of 6 random numbers. I would not generate batches of 6 random numbers till first 2 satisfy my condition

Would you elaborate?
this is an approach how the task could be done.
it uses random.choises(...) to generate 4 numbers out of a range.
to check if the first 2 numbers match, it uses a slice.

from random import choices

target_start = [1,2]
nums_count = 4

while True:
    gen_nums = choices(range(0, 10), k=nums_count)
    if gen_nums[:2] == target_start:
        print(gen_nums)
        break
Buran, what i want is exactly the first code dean and lothar came with. I am looking for the serie of random numbers with the condition where 1 or 2 are the first numbers in the random serie.
Pages: 1 2 3