Random number generation from uniform distribution

Technical Source
1 min readJun 14, 2022

--

Good afternoon, I’m currently trying to generate random numbers from a uniform distribution, but I’m not sure how to input probabilities.

For example, Let S be uniformly distributed between 70 and 130:

a=70; 
b=130;
S=a+(b-a).*rand

However, let’s say we want to generate T which is uniformly distributed: between 0.1 and 1.0 (with probability 0.75) between 1.0 and 5.0 (with probability 0.25)

Is it possible to use the rand function as normal? i.e.

a=0.1;
b=1.0;
c=5.0
T=([a+(b-a).*rand]*0.75)+([b+(c-b).*rand]*0.25)

I appreciate any feedback.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

N = 1000000;a=0.1;
b=1.0;
c=5.0;
r1 = rand(N,1);
r2 = rand(N,1);
T=(a+(b-a).*r1).*(r2<=0.75) + (b+(c-b).*r1).*(r2>0.75);figure
hist(T,0.105:0.01:4.995)

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet