From: Joe User on 21 Mar 2010 06:01 Is there any way to seed (initialize) the Excel 2003 RAND function so that subsequent calls to RAND result in a repeatable sequence? I have tried seeding the VBA Rnd function, to no avail. No surprise that the two are unrelated. It was a "hail Mary" try. Although I know how to get a repeatable Rnd sequence, I do not want to use the VBA Rnd function for my purposes. I could also easily implement my own PRNG, even using the Wichman-Hill(1982) algorithm described in support.microsoft.com/kb/828795. (Actually, I already have.) But that, too, does not suit my purposes. I want to use Excel RAND per se; no alternatives. KB 44738 suggests that there might be a RANDOMIZE variable somewhere; perhaps in an INI file, perhaps in the Registry now, or perhaps a command line switch. But I have not (yet) succeeded in locating such a variable for Excel 2003. I did try executing Excel in safemode, to no avail. Another "hail Mary" try. I even tried the command line switch /randomize=0, to no avail. A "shot in the dark". (KB 44738 refers to earlier versions of Excel in which RAND did produce a repeatable sequence by default, and it required setting the RANDOMIZE variable to change that.) Alternatively, does anyone know exactly how the Excel 2003 RAND function is seeded? Presumably by some manipulation of "system time"; but that is subject to interpretation. I can speculate as well as anyone. I am looking for the actual algorithm. KB 828795 does not explain that; and my Google searches have been fruitless (so far).
From: Charles Williams on 21 Mar 2010 08:00 I don't know of a way to seed the 2003 RAND function, or what the algorithm is, but http://support.microsoft.com/kb/828795 may help. When I want a repeatable sequence of random numbers I generate a range using RAND() and then copy-paste values to freeze the results. >Is there any way to seed (initialize) the Excel 2003 RAND function so that >subsequent calls to RAND result in a repeatable sequence? >
From: Charles Williams on 21 Mar 2010 10:26 On rereading your post I see you have already referenced KB828795 ... > >I don't know of a way to seed the 2003 RAND function, or what the >algorithm is, but >http://support.microsoft.com/kb/828795 >may help. > >When I want a repeatable sequence of random numbers I generate a >range using RAND() and then copy-paste values to freeze the results. > >>Is there any way to seed (initialize) the Excel 2003 RAND function so that >>subsequent calls to RAND result in a repeatable sequence? >>
From: Joe User on 21 Mar 2010 10:41 "Charles Williams" <Charles(a)DecisionModels.com> wrote: > http://support.microsoft.com/kb/828795 may help. Y'don't 'spose that's the very same support.microsoft.com/kb/828795 that I referred to in my posting? ;-) Y'had to read all the way down to the 4th paragraph (6th sentence). No, it does not help. > When I want a repeatable sequence of random numbers > I generate a range using RAND() and then copy-paste > values to freeze the results. Yeah, I 'spose I could make that work for my purposes. I am still interested in how to seed RAND or how it is seeded, if only to satisfy my curiosity. ----- original message ----- "Charles Williams" <Charles(a)DecisionModels.com> wrote in message news:292cq595ehdu5vk1p7220to43mge2qcq1n(a)4ax.com... > > I don't know of a way to seed the 2003 RAND function, or what the > algorithm is, but > http://support.microsoft.com/kb/828795 > may help. > > When I want a repeatable sequence of random numbers I generate a > range using RAND() and then copy-paste values to freeze the results. > >>Is there any way to seed (initialize) the Excel 2003 RAND function so that >>subsequent calls to RAND result in a repeatable sequence? ----- previous message ----- "Joe User" <joeu2004> wrote in message news:e4ilG2NyKHA.3408(a)TK2MSFTNGP06.phx.gbl... > Is there any way to seed (initialize) the Excel 2003 RAND function so that > subsequent calls to RAND result in a repeatable sequence? > > I have tried seeding the VBA Rnd function, to no avail. No surprise that > the two are unrelated. It was a "hail Mary" try. > > Although I know how to get a repeatable Rnd sequence, I do not want to use > the VBA Rnd function for my purposes. > > I could also easily implement my own PRNG, even using the > Wichman-Hill(1982) > algorithm described in support.microsoft.com/kb/828795. (Actually, I > already have.) But that, too, does not suit my purposes. > > I want to use Excel RAND per se; no alternatives. > > KB 44738 suggests that there might be a RANDOMIZE variable somewhere; > perhaps in an INI file, perhaps in the Registry now, or perhaps a command > line switch. But I have not (yet) succeeded in locating such a variable > for > Excel 2003. > > I did try executing Excel in safemode, to no avail. Another > "hail Mary" try. I even tried the command line switch /randomize=0, to no > avail. A "shot in the dark". > > (KB 44738 refers to earlier versions of Excel in which RAND did produce a > repeatable sequence by default, and it required setting the RANDOMIZE > variable to change that.) > > Alternatively, does anyone know exactly how the Excel 2003 RAND function > is > seeded? > > Presumably by some manipulation of "system time"; but that is subject to > interpretation. I can speculate as well as anyone. I am looking for the > actual algorithm. KB 828795 does not explain that; and my Google searches > have been fruitless (so far).
From: Dana DeLouis on 26 Mar 2010 17:10
Hi. As a side note, this is interesting because I can't get vba's Rnd values using your equation at Machine Precision. However, if we bump the precision up just a little, then we can do what Rnd does. I wonder what Excel is actually doing? Very interesting. :>) Private Sub Workbook_Open() Dim a, b, k Dim x Dim R a = 1140671485 b = 12820163 k = 2 ^ 24 '// First 50 Rnd calls For R = 1 To 50 Cells(R, 1) = Rnd Next R '// Double as in Workbook x = CDbl(327680) For R = 1 To 50 If x < 1 Then x = x * k x = dMod(x * a + b, k) / k Cells(R, 2) = x Next R '// Higher Precision for vba x = CDec(327680) For R = 1 To 50 If x < 1 Then x = x * k x = dMod(x * a + b, k) / k Cells(R, 3) = x Next R Range("A1:C50").NumberFormat = "0.00000000000000000" End Sub >> Excel rnd VBA Rnd >> 0.7055475115776060 0.7055475115776060 >> 0.5334241390228270 0.5334240198135370 >> 0.5581560134887690 0.5795186161994930 >> 0.5320560932159420 0.2895624637603760 >> 0.7160687446594230 0.3019480109214780 >> 0.0968921184539795 0.7747400999069210 >> 0.4058379530906680 0.0140176415443420 >> 0.3854335546493530 0.7607235908508300 >> 0.9148474335670470 0.8144900202751150 >> 0.3595037460327150 0.7090378999710080 <snip> = = = = = = = Dana DeLouis |