简体   繁体   中英

How to emulate normal distribution data by actual, real life events, instead of using a math formula?

I am trying to generate some Bell Shape data (Normal Distribution). There are some math formula to achieve that, but I am hoping to emulate it by natural, daily events that happen in real life.

For example, I am saying, for 50 students, assuming they have a 70% chance of getting a question in a multiple choice exam correct, for 100 questions. So what score does each student get? I have the code in JavaScript:

 students = Array.from({ length: 50 }); students.forEach((s, i, arr) => { let score = 0; for (let i = 0; i < 100; i++) { if (Math.random() >= 0.3) score++; } arr[i] = score; }); console.log(students);

But the result doesn't seem like a normal distribution. For example, I got:

[
  69, 70, 67, 64, 71, 72, 77, 70, 71, 64, 74,
  74, 73, 80, 69, 68, 67, 72, 69, 70, 61, 72,
  72, 75, 63, 68, 71, 69, 76, 70, 69, 69, 67,
  63, 65, 80, 70, 62, 68, 63, 73, 69, 64, 79,
  79, 72, 72, 70, 70, 66
]

There is no student who got a score of 12 or 20, and there is no student who got a score of 88 or 90 or 95 (the students who can get an A grade). Is there a way to emulate a real life event to generate normal distribution data?

Two issues:

  • 100 students may be a bit too small a sample to produce such a pattern; 10000 students will give a better view.
  • You can better visualise the statistics by counting the number of students that have a given score. So you would get a count per potential score (0..100).

And now you can see the Bell curve:

 let students = Array.from({ length: 10000 }); let studentsWithScore = Array(101).fill(0); students.forEach(() => { let score = 0; for (let i = 0; i < 100; i++) { if (Math.random() >= 0.3) score++; } studentsWithScore[score]++; }); console.log(studentsWithScore);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM