Python Forum
find random numbers that are = to the first 2 number of a list.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find random numbers that are = to the first 2 number of a list.
#11
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
Reply
#12
Why are you trying to find a series that matches? What is the pupose behind your code?
Reply
#13
looking for reccuring mathematical pattern.
Reply
#14
Is order important?
Reply
#15
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.
Reply
#16
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.
Reply
#17
At a second per serie of numbers to check it could take up to 45 days before i get a return.
Reply
#18
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?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#19
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
Reply
#20
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,721 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 576 Nov-27-2023, 05:17 PM
Last Post: janeik
  Sample random, unique string pairs from a list without repetitions walterwhite 1 465 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  find the sum of a series of values that equal a number ancorte 1 508 Oct-30-2023, 05:41 AM
Last Post: Gribouillis
  Program to find Mode of a list PythonBoy 6 1,114 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Delete strings from a list to create a new only number list Dvdscot 8 1,555 May-01-2023, 09:06 PM
Last Post: deanhystad
  List of random numbers astral_travel 17 2,725 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Find (each) element from a list in a file tester_V 3 1,238 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Remove numbers from a list menator01 4 1,348 Nov-13-2022, 01:27 AM
Last Post: menator01
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,530 Oct-23-2022, 11:13 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020