Python Random Function without using random module

后端 未结 6 1070
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2021-02-09 17:53


    here we need to understand one thing that a random varible is generated by using random values that gives at run time. For that we need time module

    time.time() gives you random values (digits count nearly 17). we need in milliseconds so we need to multiply by 1000 if i need the values from 0-10 then we need to get the value less than 10 that means we need below: time.time%10 (but it is in float we need to convert to int) int(time.time%10)


    import time
    
    def rand_val(x):
    
        random=int(time.time()*1000)
    
        random %= x
    
        return random
    
    x=int(input())
    
    print(rand_val(x))
    

提交回复
热议问题