Random sampling with rand(Uniform(0,1), n)

Hello everyone,

I’m trying to collect some random samples from Uniform distribution Uniform(0,1) . What I observe is that most of values are around 10^-1 range so like 0.1, 0.3, 0.7 something like that but it rarely hits low values like 0.001 or 0.0001 etc. Is there a reason for that ? it feels it more preference is given to 0.1 interval based values. Can someone explain it?

example : 100 samples

julia> rand(Uniform(0,1),100)
100-element Vector{Float64}:
 0.5249199608023001
 0.8031983130758128
 0.8255224947009021
 0.5748273447861918
 0.7031471781803088
 0.7478197128715807
 0.25466920525995174
 0.7471145830396936
 0.5517171665716666
 0.31763847227150077
 0.26487735444679683
 0.574012819213797
 0.7000744042730915
 0.25639758407957514
 0.02485313070819639
 0.5219209193763207
 0.9804886461626476
 0.8636020186367837
 0.9066537849666537
 0.9939500285179668
 0.1326313817064928
 0.1435310329085726
 0.5860093863545383
 0.3384714682313438
 0.712930698005653
 0.33033492596197866
 0.410738576897027
 0.2557602094075623
 0.7672251198764982
 0.5388842460457809
 0.26362446439671405
 0.37832673427682195
 0.5732485182159951
 0.884024870111885
 0.16737082555064164
 0.2565762992185219
 ⋮
 0.06849017259202361
 0.36313676382229976
 0.8299547876243945
 0.9284924529639013
 0.4672929521124921
 0.6449826822277465
 0.7489408319972285
 0.16709740118211858
 0.5991365567380487
 0.32083104127801687
 0.07747665844536411
 0.16622466716606854
 0.8395424194498875
 0.09390760130506948
 0.42760973525018664
 0.15639675823890486
 0.2874074593457234
 0.3234676226656664
 0.2616021199731944
 0.8032550975640945
 0.12002343103333879
 0.0010312551128017766
 0.11931758177921736
 0.4610261883217075
 0.21579799460089233
 0.7991646952708531
 0.13400617332152565
 0.6937386455527602
 0.079334624037112
 0.7085948326010761
 0.16069241487584074
 0.8002060607501278
 0.3498751803361242
 0.6490590082877452
 0.4150492809084607
 0.7312865303310884

Thank you :slight_smile:

Try to increase you number of samples and make a histogram instead of observing with naked eyes.

2 Likes
julia> using Distributions, GLMakie

julia> hist(rand(Uniform(0, 1), 1_000_000); bins = 0:0.0001:1.0)

image

2 Likes

This is just what a uniform distribution means — think about the probabilities.

For a uniform distribution in [0,1], the probability of generating a number \le 0.001 is 0.001one in 1000. It generates a number between 0.1 and 1 (= 0.999…) with 90% probability.

4 Likes

Yeah… I realised that a little late :sweat_smile:.

Thank you :slight_smile: