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

ROHAN RASKAR rohanraskar24 at gmail.com
Mon Sep 7 16:45:34 EDT 2020


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)


On Tue, Sep 8, 2020 at 1:09 AM ROHAN RASKAR <rohanraskar24 at gmail.com> wrote:

> Dear Sir/Ma'am,
>                           I'm a student and beginner for learning python
> language. I want to generate 1000 random numbers which are normally
> distributed with mean 0.6 and 0.2 standard deviations. I tried a lot but I
> am getting some errors in code. Could you guide me?  Thank you so much.
>
> I attached my code file, please help me.
>
>
>


More information about the Tutor mailing list