Recover Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttp://yahoo.com/
COST (GBP)
this unit 6.24
sub units 10.02
add licence
0

Random Sample

viewed 7691 times and licensed 126 times
Generates random numbers following a Poisson distribution.
Controller: CodeCogs

buy now add cart

Dependents

Info

Interface

C++
Excel

Class RandomSample

The Poisson distribution is used to model the number of events occurring within a given time interval. The formula for the Poisson probability mass function, which we also use with this random number generator is

where \mu is the shape parameter indicating the average number of events in the given time interval.

Using this class, the diagram below is generated from two distinct sequences of 1000 random numbers. Each pair of numbers are plotted against each other, to illustrate the Poisson behaviour of this non-uniform random number generator.

1/poisson.png
+
The following example displays 40 random floating point numbers from a Poisson distribution. It uses two different generators to achieve this. The first generator uses a particular value to initialize the seed, while the second one is using the system timer. Notice that it was necessary to divide the timer by the <em> MERSENNEDIV </em> value in order to keep the seed in the interval from 0 to 1. Since the seed of the first generator is never changed, the first 20 numbers will always remain the same. However since the second generator is initialized via the system timer, the next 20 numbers will obviously vary with each execution of the program,

In the example output you will find 20 numbers corresponding to the output of the first generator.

Speed

The average running time for generating 100,000,000 random numbers using this class on a 750MHz microprocessor is 56 seconds.

Example 1

#include <iostream>
#include <time.h>
 
#include <codecogs/stats/dists/discrete/poisson/randomsample.h>
 
int main()
{
    Stats::Dists::Discrete::Poisson::RandomSample A(53.29, 0.15);
    Stats::Dists::Discrete::Poisson::RandomSample B(61.47, time(0) / MERSENNEDIV);
 
    for (int i = 0; i < 20; ++i)
        std::cout << A.genInt() << " ";
 
    std::cout << std::endl << std::endl;
 
    for (int i = 0; i < 20; ++i)
        std::cout << B.genInt() << " ";
    std::cout << std::endl;
    return 0;
}
Output:
51 60 51 68 50 50 45 61 58 49 55 38 48 58 52 60 52 48 48 48

References

  • NIST/SEMATECH e-Handbook of Statistical Methods, http://www.itl.nist.gov/div898/handbook/
  • The Newran03 random number generator library of Robert Davies, http://www.robertnz.net/nr03doc.htm

Authors

Lucian Bentea (June 2005)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of RandomSample

RandomSample

 
RandomSampledoublemu
doubleseed = 0.8476 )[constructor]
Constructor that sets up the class variables and initializes the associated random number generator with the given seed.
seedDefault value = 0.8476


Sample

 
intsampledoublemu
doubleseed = 0.123 )
This function is a simple wrapper around the randomsample class provided in this module. It uses a static to keep a single instance of this class, so that each call to this function returns a new random number. As a result this function is not necessarily thread safe, in the sense that with identical initial seed, the sequence of random numbers may differ on a multitasking or multi threaded system.

The seed is only set on the first call to this function. Thereafter this parameter is ignored. If you do no want to set the seed, then we suggest you use the system clock the first time you call this function, i.e.
#include <time.h>
 ...
 sample(mu, time(0) / MERSENNEDIV);
If you require more advance behaviour, we strongly recommend using the underlying class randomsample (above).

Parameters

muaverage number of events
seedsets the initial seed for the random generator. Only used in the first call to this function
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


 

Page Comments

 
Page:  

CLauer\′s Photo
11 Mar 11, 5:40PM
(1 reply)
Excel module
How do I use the excel module? I tried to open it in Excel 2010 but the format is unreadable.
CodeCogs\′s Photo
6 Apr 11, 6:37PM
Hi. We don't support 2010 yet. But there is an ongoing project to implement for 2010.
nirav\′s Photo
24 Nov 08, 5:35AM
(1 reply)
can i have example shows to generate random number?
can i have one example illustration which shows how value 'k' returned by poisson random generator function??
will\′s Photo
24 Nov 08, 8:35AM
I thought I did!

Goto this page http://www.codecogs.com/d-ox/stats/dists/discrete/poisson/randomsample.php

There is an example half way down.
nirav\′s Photo
12 Nov 08, 4:55AM
(1 reply)
how to generate poisson with single argument mean?
In my algorithm i have to generate random number using poisson(lembda) where lembda is the single argument which is updated by code.now i know the equation of poisson and the value of lembda but i dont know which value of k should i take in equation of poisson to get the random number.can u explain with one example as initially my lembda =1.

F(k,λ ) = [(λ)^k * e^(-λ )] / k!

what value should i take as k in above equation so that it generates random number >= 1????
will\′s Photo
12 Nov 08, 8:15AM
In the normal poisson pdf k is the number of events, while λ is mean.

In your random generator, you shouldn't be entering k, this should be returned by the generator.
nirav\′s Photo
11 Nov 08, 5:27AM
(1 reply)
What is seed?
what is seed? and how actually i set the value of seed initially as i am using poisson dist as simulating the process of sampling with replacement??
CodeCogs\′s Photo
11 Nov 08, 7:56AM
Computers aren't able to produce random numbers, instead they produce a sequence of numbers which repeat very infrequently - this number is usually very large with any good random generator, e.g. after 2^250 digits. In addition is you look at any smaller sequence then it'll look entirely random.

Where you are in this sequence is the seed. Therefore if you reset the seed to the same value each time before generating random numbers, then you'll recreate the same sequence each and every time.

Because you often don't want this, a lot of people use the system clock to set the seed. This approach is nearly perfectly random in its initialization, because when a program starts is usually determined by some user action - and humans are very random!. In the example at the top of this page, they used.
Stats::Dists::Discrete::Poisson::RandomSample B(61.47, time(0) / MERSENNEDIV);
where time(0) is the system time and MERSENNEDIV is just a constant that reduced the return from time() to something between 0 and 1.
 
 Format Excel Equations

  You must login to leave a messge