[Tutor] Need help to generate random number without library functions.

Richard Damon Richard at Damon-Family.org
Mon Sep 7 19:10:08 EDT 2020


On 9/7/20 4:45 PM, ROHAN RASKAR wrote:
> This is my code :
>
>
>  import numpy as np
> import math
> def normal():
>     n=1000 ##number of random numders
>     u=0.6 ##mean
>     sd=0.2 ##standard deviation
>     value = []
>     x={}
>     fd=[]
>     pi=math.pi
>     r = 2.0*sd**2
>     a = x - u
>     d = math.sqrt(2.0*pi)
>     e = math.exp(-a*a)
>
> while len(value) < n:
>      if 0 < x < 10:
>        value = (e/r)/(d*0.2)
>      fd[int(value)] = fd.get(int(value), 0) + 1
>      values.append(value)
>      print(value)
>
>
Your defining a function call normal but never calling it. And that
function sets up a bunch of local variables that it then doesn't use.

-- 
Richard Damon



More information about the Tutor mailing list