Re: RE: Quick "Random[]" question
- To: mathgroup at smc.vnet.net
- Subject: [mg41878] Re: [mg41847] RE: [mg41831] Quick "Random[]" question
- From: Bobby Treat <drmajorbob-MathGroup3528 at mailblocks.com>
- Date: Sat, 7 Jun 2003 11:45:02 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I did a similar experiment, and found it would take about 1.649328667383962*^14 random draws to get a result within 10^-16 of either end-point f[n_Integer] := Block[{min = 10.^(-n), count = 0, max}, max = 1 - min; {Timing[While[min < Random[] < max, count++]][[1, 1]], count}] counts = f /@ Range[4, 8] {{0.032, 4476}, {0.25, 37250}, { 1.046, 160748}, {8.125, 1236061}, {136.344, 20678316}} Fit[Log@times[[All, 2]], {1, z}, z] Exp[%] /. z -> 16 - 3 6.24483 + 2.03783 z 1.649328667383962*^14 I used Regress to check how significant the fit was, and it was VERY good. On my machine it would take about 29 years: Fit[Log@save[[All, 1]], {1, z}, z] Exp[%]Second /. z -> 16 - 3 % /. Second -> Year/(365.25*24*60*60) -5.61334 + 2.01956 z 9.210255557287763*^8*Second 29.1855 Year On the other hand, it could happen today, on the next random draw!! Bobby -----Original Message----- From: Wolf, Hartmut <Hartmut.Wolf at t-systems.com> To: mathgroup at smc.vnet.net Subject: [mg41878] [mg41847] RE: [mg41831] Quick "Random[]" question >-----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: [mg41878] [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 ndigit 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