Generate random number between -Inf and 0.5
Show older comments
Z = [-Inf 0.5326 0.6 0.6674 Inf]
I have above intervals like (-Inf 0.5326) (0.5326 0.6) (0.6 0.6674) (0.6674 Inf). Between these intervals, I need to produce random numbers. How do you make the first and last samples? I'm trying to use the formula below, but it's not working. Is there a method to do this, and if so, what is wrong with my formula and how can I fix it? Can anyone please help me with this. Thanks in advance
if i =1
sample(i) = randi([-10^5, za(i+1)],1)
else if i = n
sample(i) = randi([za(i-1), 10^5],1)
Accepted Answer
More Answers (1)
Walter Roberson
on 8 Sep 2021
0 votes
Random numbers with what distribution?
You are looking for infinite tails, but in double precision, representable values get less dense as the magnitude gets larger. The distance between adjacent numbers at 10^20 is 2^14; the distance between adjacent numbers at 10^40 is 2^80. So it is not possible to be able to distinguish between 10^20+0.6 and 10^20+0.6674 (for example) -- not if you use double precision numbers.
So if you want uniform random distribution you are going to have problems, unless you switch to a different representation.
How many different values need to be represented in the range (0.5326 0.6) ? 674 different values, as in 0.5326, 0.5327, 0.5328, ... 0.5998, 0.5999, .6000 ? How many different values betwee -inf and 0.5326 need to be represented ? If you wanted 2^53 different values to be represented between -realmax and 0.5326 and you want uniform random distribution, then the numbers would have to be roughly 10^291 apart. If you went for 2^64 different representable values, they would have to be about 2.4*10^288 apart
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!