Random number with a ratio of 1: 2

I need to generate two random sets of matrices. Each of which contains 3 digits of digits from 2 to 10

like

matrix 1: 994,878,129,121

matrix 2: 272,794,378,212

the numbers in both matrices must be greater than 100 and less than 999

BUT

the average value for both matrices should be in the ratio of 1: 2 or 2: 3, which will ever limit user input

My math skills are a bit limited, so any ideas how I can do this?

+3
source share
2 answers

To do this, you must know how many numbers are in each list. I assume from your example that each of them has four numbers.

  • Fill the first list with four random numbers.
  • Calculate the average from the first list.
  • 2 3/2, , . .
  • 4. .
  • 3 .
  • 5 4. .
  • 6 , 5.

, , .

+2

, s1.

s1= [ random.randint(100,999) for i in range(n) ]

s2, , . , .

, 100 999, 550. - , , .

, .

+1

Source: https://habr.com/ru/post/1698748/


All Articles