Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Generate random numbers according to custom distribution

Subject: Generate random numbers according to custom distribution

From: Kurt

Date: 27 Aug, 2010 14:12:23

Message: 1 of 5

Hi,

For testing a scheduling engine I have to generate random trip data. However, I'd like the start times of my trips to be random but according to a custom distribution (http://www.woofiles.com/dl-204264-wuBo0gSg-Distribution.jpg). So for example, trip start times should be more likely to be during midday than during the evening.
Is this possible to do this using the distribution fitting tool and the 'rand' command or is there any other way of achieving this?

Thanks for the help!

Best regards,
Kurt

Subject: Generate random numbers according to custom distribution

From: Tom Lane

Date: 27 Aug, 2010 15:03:45

Message: 2 of 5

> For testing a scheduling engine I have to generate random trip data.
> However, I'd like the start times of my trips to be random but according
> to a custom distribution
> (http://www.woofiles.com/dl-204264-wuBo0gSg-Distribution.jpg). So for
> example, trip start times should be more likely to be during midday than
> during the evening. Is this possible to do this using the distribution
> fitting tool and the 'rand' command or is there any other way of achieving
> this?

Kurt, if you want to sample hours of the day with unequal probabilities for
the different hours, you could use the randsample function with the W
argument specifying the probabilities.

If you want continuous time, you'd have to decide on the distribution of
times between hours. One way might be to use randsample as above and then
use rand to add a fractional hour. This would give you different
probabilities for different hours, but a uniform probability within the
hour.

-- Tom

Subject: Generate random numbers according to custom distribution

From: Kurt

Date: 28 Aug, 2010 07:27:05

Message: 3 of 5

"Tom Lane" <tlane@mathworks.nospam.com> wrote in message <i58k4i$60e$1@fred.mathworks.com>...
> > For testing a scheduling engine I have to generate random trip data.
> > However, I'd like the start times of my trips to be random but according
> > to a custom distribution
> > (http://www.woofiles.com/dl-204264-wuBo0gSg-Distribution.jpg). So for
> > example, trip start times should be more likely to be during midday than
> > during the evening. Is this possible to do this using the distribution
> > fitting tool and the 'rand' command or is there any other way of achieving
> > this?
>
> Kurt, if you want to sample hours of the day with unequal probabilities for
> the different hours, you could use the randsample function with the W
> argument specifying the probabilities.
>
> If you want continuous time, you'd have to decide on the distribution of
> times between hours. One way might be to use randsample as above and then
> use rand to add a fractional hour. This would give you different
> probabilities for different hours, but a uniform probability within the
> hour.
>
> -- Tom

That did the trick. Thanks a lot!

Subject: Generate random numbers according to custom distribution

From: ImageAnalyst

Date: 28 Aug, 2010 13:28:02

Message: 4 of 5

If people don't have the randsample() function (like I don't), you can
do it by computing the cdf of your desired pdf, then inverting your
cdf and running a uniform distribution of random numbers through it.
I've given more details a few weeks ago with some guy who wanted a
Rayleigh distribution if anyone is interested.

Subject: Generate random numbers according to custom distribution

From: Kevinos

Date: 11 May, 2013 18:58:07

Message: 5 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <71db26a7-0921-4dab-b943-fd7d17fe7829@v41g2000yqv.googlegroups.com>...
> If people don't have the randsample() function (like I don't), you can
> do it by computing the cdf of your desired pdf, then inverting your
> cdf and running a uniform distribution of random numbers through it.
> I've given more details a few weeks ago with some guy who wanted a
> Rayleigh distribution if anyone is interested.


I'm planning on using this method, would you be able to provide a link to this thread, ImageAnalyst? Thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us