MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Quick "Random[]" question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41847] RE: [mg41831] Quick "Random[]" question
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 7 Jun 2003 00:08:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Jonathan Greenberg [mailto:greenberg at ucdavis.edu]
To: mathgroup at smc.vnet.net
>Sent: Friday, June 06, 2003 3:51 PM
>To: mathgroup at smc.vnet.net
>Subject: [mg41847] [mg41831] Quick "Random[]" question
>
>
>Is it possible to get 0.0 and 1.0 from Random[] (e.g. is the x=Random[]
>0<=x<=1 or 0<x<1 ?)
>
>--j
>

Jonathan,

mathematically speaking, the question appears, to me, to be of no relevance
(target set of measure zero).

The computational side might be different, but observe:

In[3]:= n = 6;
In[4]:=
(res = {};
    With[{min = 10.^(-n + 1), max = 1. - 10^(-n + 1)}, 
      Do[If[(x = Random[]) < min || x > max, res = {res, x}], {10^n}]] ;
    Sort[Flatten[res]]) // Timing

In[5]:= % // InputForm
Out[5]//InputForm=
{35.792*Second, {8.169411304711355*^-7, 
  2.715084457434458*^-6, 3.384771903159169*^-6, 
  3.453568531851855*^-6, 4.178183919986743*^-6, 
  5.300288977082681*^-6, 6.6703436910034615*^-6, 
  8.29779495011354*^-6, 9.257352686970702*^-6, 
  0.9999932347987964, 0.9999939369474545, 
  0.9999948585417587, 0.9999961986226781, 
  0.9999962344951426, 0.9999968296839472, 
  0.9999982857366351, 0.9999987538196398, 
  0.9999990610373628, 0.9999993741303179}}

In[6]:= %%[[1]] * 10^10 /. Second -> Year /(365.25*24*60*60)
Out[6]= 11341.8 Year

I simply havn't got that time.


In Help there is a remark:

Random[Real, range, n] generates an n­digit pseudorandom real number. Both
leading and trailing digits may be chosen as 0. 


But, as ever, regard:

In[15]:= Random[Real, {0, 1}, 17]
Out[15]= 0.025225070291350781

In[16]:= Random[Real, {0, 1}, 16]
Out[16]= 0.951953

In[17]:= MachineNumberQ /@ {%%, %}
Out[17]= {False, True}


You may however control the case if you generate random Integers -- of a
certain range -- and convert to reals by yourself.


--
Hartmut Wolf


  • Prev by Date: Re: Re: Multiplying permutations
  • Next by Date: Re: Taking a function as a parameter of a function
  • Previous by thread: RE: Quick "Random[]" question
  • Next by thread: Re: Quick "Random[]" question