Generating List of N Random Numbers Between a Range of Numbers

后端 未结 2 1648
误落风尘
误落风尘 2021-01-27 09:13

I\'d like to generate a list of n_length consisting of randomly generated numbers within a defined range. What I\'d like to know is whether I\'m missing something built-in, som

相关标签:
2条回答
  • 2021-01-27 09:34

    I believe you are looking for

    rand_list = [randrange(700, 1500) for _ in xrange(100)]
    
    0 讨论(0)
  • 2021-01-27 09:36

    I think this is better if you don't care about the distribution:

    >>> random.sample(xrange(700, 1500), 100)
    
    0 讨论(0)
提交回复
热议问题