Python- How to generate random integers with multiple ranges?

后端 未结 6 1979
忘掉有多难
忘掉有多难 2021-01-12 01:25

I\'ve run into confusion in generating X amount of random integers from different sets of (a,b). For example, I would like to generate 5 random integers coming from (1,5), (

6条回答
  •  醉梦人生
    2021-01-12 01:31

    for i in (randint(1,5),randint(9,15),randint(21,27)):
        print i
    

    This foor loop will generate 3 random numbers one from the first range supplied, another for second range and last one for last range and prints every one on output. Yours print is out of the foor loop and prints only the last random number from the last range given.

提交回复
热议问题