Python Random Function without using random module

后端 未结 6 1068
渐次进展
渐次进展 2021-02-09 17:14

I need to write the function -

random_number(minimum,maximum)

Without using the random module and I did this:

import time

def         


        
6条回答
  •  别跟我提以往
    2021-02-09 17:43

    Idea is to get number between 0 and 1 using time module and use that to get a number in range.Following will print 20 numbers randomly in range 20 and 60

    from time import time
    
    def time_random():
     return time() - float(str(time()).split('.')[0])
    
    def gen_random_range(min, max):
     return int(time_random() * (max - min) + min)
    
    if __name__ == '__main__':
     for i in range(20):
         print gen_random_range(20,60)
    

提交回复
热议问题