 |

11-15-2000, 03:06 PM
|
|
|
Std. Normal Random Number Generation
|
|
I have just started programming in Visual Basic, and for one of my assignments, I have to figure out how to generate standard normal random numbers. Can someone give me an advice, or show how to do it?
The numbers generated should be normally distributed with an expoected value of 0 and standard deviation of 1. When I got enough of them, they should form a bell shaped histogram.
|
|

11-15-2000, 03:15 PM
|
|
Verbose Coder
Retired Moderator * Guru *
|
|
Join Date: Dec 1999
Location: Phoenix, Arizona
Posts: 3,011
|
|
Re: Std. Normal Random Number Generation
Are you looking for some kind of Newtonian formula for generating random numbers or simply how to get VB to produce random numbers?
If the answer is just how to do it in VB then somewhere at the beginning of your code place the 'Randomize' statement, which causes the random number generator to be seeded with the time, then use the Rnd function like so:
Randomize ' Seed the built in random number generator. Only need this line once.
intRandomNumber = Int(Rnd * 10) + 1 ' Generate a number from 1 to 10.
Not sure if this helps,
Good luck,
Paul
|
|

11-15-2000, 05:16 PM
|
|
|
Re: Std. Normal Random Number Generation
|
|
Thanks, but what I am looking for is, the numbers generated by the system should be normally distributed with an expected value of zero and a standard deviation of 1. In addition to that, 90% of these numbers generated should be in the boundary of -2 and +2. And when I get enough of them, they should have a nice bell shaped histogram.So, I need such a random number generator.
|
|

11-15-2000, 06:13 PM
|
|
Senior Contributor
|
|
Join Date: Apr 2000
Location: Edge City, CA
Posts: 799
|
|
Re: Std. Normal Random Number Generation
Paul,
To to seed the randomizer with the time you need to feed it with the 'Timer' function:
Randomize Timer
BTW: I have no idea how to get a Bell curve out of VB.
->Noah
|
|

11-16-2000, 12:18 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Re: Std. Normal Random Number Generation
One possible way would be to map a "normal" random sequence into a "bell curve" sequence.
For instance, I could have an array of, say 1000 elements. Each element is the probability of being on that particular part of the bell curve. Ie. If you graph this array, you would essentially have a bell curve.
You then generate a random number and figure out which element of the array it falls in. You then use the array index to return your "bell curved" random number.
The drawback of this method is that the numbers have an incremental value. But you can increase the array size to compensate.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

11-16-2000, 09:29 AM
|
|
Verbose Coder
Retired Moderator * Guru *
|
|
Join Date: Dec 1999
Location: Phoenix, Arizona
Posts: 3,011
|
|
Re: Std. Normal Random Number Generation
Noah,
If you omit the Number after the Randomize statement VB uses the system timer by default - at least that's what MSDN for VB6 states.
Cheers,
Paul
|
|

11-16-2000, 12:53 PM
|
|
Senior Contributor
|
|
Join Date: Apr 2000
Location: Edge City, CA
Posts: 799
|
|
Re: Std. Normal Random Number Generation
A Thousand Pardons Sir,
Old habits die hard, I was not aware of that. I don't think it used to be that way.
I might just go on doing the old way so there's not doubt about what's seeding the generator.
Thanx,
->Noah
|
|

11-16-2000, 01:34 PM
|
|
|
Re: Std. Normal Random Number Generation
I am confused, yalingecer is obviously reading this stuff from an exam paper or something, here is what I have a problem with.
We are looking for a random number that is 'normally distributed with an expected value of zero and a deviation of 1'. This does not sound random.
Expect to be 0, but can have a deviation of 1, deviations are notmally caused not generated (I think that makes sense).
'In addition, 90% of these should be in the boundary of -2 and +2.' This does not tie up with the 'normally 0 but can be deviated by 1'.
For 90% of the results to be in the boundary of -2 and +2 the boundry must be larger so the other 10% can fall outside.
And the bell thing, surely a mathmatically calculated predefined shape cannot be created using pure randomisation.
I'm confused!!!
Is it the holidays in the rest of the world, as alot of people seem to trying to get their homework done before they go back to school.
|
|

11-17-2000, 10:04 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Re: Std. Normal Random Number Generation
I actually did this one time. I was playing around with a game I was coding and I needed a routine to calculate hit location. What I needed was a function that returned a number that represented the number of hexes I missed by (0 of course was a dead centre hit). I wanted a bell curve distribution with the peak at dead centre, tapering off at the extremes. I wound up using an array as I mentioned above.
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|