From: Lieven Marchand
Subject: RANDOM with bignum argument
Date: 
Message-ID: <m3d7asd2xv.fsf@localhost.localdomain>
In ACL 5.0 the RANDOM function doesn't work with bignum arguments
above a certain size.

USER(8): (random (fac 200))

Error: This integer is too large to be converted to a double-float:
       788657867364790503552363213932185062295135977687173263294742
5332443594499634033429203042840119846239041772121389196388302576427902426371050
6192662495282993111346285727076331723739698894392244562145166424025403329186413
1227428294853277524242407573903240321257405579568660226031904170324062351700858
796178922222789623703897374720000000000000000000000000000000000000000000000000
  [condition type: SIMPLE-ERROR]

Is this a bug or is this allowed by the standard as an implementation
limitation?

-- 
Lieven Marchand <···@wyrd.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.

From: Duane Rettig
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <4bsqcct1t.fsf@beta.franz.com>
Lieven Marchand <···@wyrd.be> writes:

> In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> above a certain size.
> 
> USER(8): (random (fac 200))
> 
> Error: This integer is too large to be converted to a double-float:
>        788657867364790503552363213932185062295135977687173263294742
> 5332443594499634033429203042840119846239041772121389196388302576427902426371050
> 6192662495282993111346285727076331723739698894392244562145166424025403329186413
> 1227428294853277524242407573903240321257405579568660226031904170324062351700858
> 796178922222789623703897374720000000000000000000000000000000000000000000000000
>   [condition type: SIMPLE-ERROR]
> 
> Is this a bug or is this allowed by the standard as an implementation
> limitation?

Well, I consider it to be not nice.  However, you _are_ using a fairly
old version...

CL-USER(1): (defun fac (n) (if (zerop n) 1 (* n (fac (1- n)))))
FAC
CL-USER(2): (random (fac 200))
385659726072417266815163346569130849728919695862094262266274273263923094
436104919585302931505846861875583284492310271183012782027360432948601794
795242668701951621728428087664436310376914151798502369576365955053956795
794966417095205415398617584931778601463269451936770033379222514292662207
749671157526124763860538179207685875748568921235828711357784357467516035
207239114678582
CL-USER(3): 

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: eric dahlman
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <tz4r8z8l8ob.fsf@sibelius.cs.colostate.edu>
Lieven Marchand <···@wyrd.be> writes:

> In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> above a certain size.
> 
> USER(8): (random (fac 200))
> 
> Error: This integer is too large to be converted to a double-float:
        [snip big int]
>   [condition type: SIMPLE-ERROR]
> 
> Is this a bug or is this allowed by the standard as an implementation
> limitation?

Even if this was just an implementation limitation I think that you
should look into getting your randomness from a different source.
Pseudo-random number generators like random are notoriously bad when
used to generate more that a handful of bits, even the 32 they claim
to do in one shot is really tenuous.  In general if you start asking
for bigger chunks like the amount you would need for (random (fac
200)) you need a real source of randomness.  Check out
www.lavarand.com for a system out of SGI for doing this.

-Eric


> 
> -- 
> Lieven Marchand <···@wyrd.be>
> Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: Duane Rettig
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <47l10crzp.fsf@beta.franz.com>
eric dahlman <·······@cs.colostate.edu> writes:

> Lieven Marchand <···@wyrd.be> writes:
> 
> > In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> > above a certain size.
> > 
> > USER(8): (random (fac 200))
> > 
> > Error: This integer is too large to be converted to a double-float:
>         [snip big int]
> >   [condition type: SIMPLE-ERROR]
> > 
> > Is this a bug or is this allowed by the standard as an implementation
> > limitation?
> 
> Even if this was just an implementation limitation I think that you
> should look into getting your randomness from a different source.
> Pseudo-random number generators like random are notoriously bad when
> used to generate more that a handful of bits, even the 32 they claim
> to do in one shot is really tenuous.

This is not true.  Random numbers larger than 32-bits are easy to
generate.  And with patches, Allegro CL 6.0 does a good job of this.
We use the Mersenne Twister Algorithm, which has a large cycle.

>  In general if you start asking
> for bigger chunks like the amount you would need for (random (fac
> 200)) you need a real source of randomness.  Check out
> www.lavarand.com for a system out of SGI for doing this.

True randomness is not always desirable.  One of the problems with
true randomness is that at a local level, coincidence can make the
generator look downright repetitive.  And when you have to test
softare or hardware, sometimes it is not randomness you want but
relatively even distribution, which gives you a higher confidence
of coverage in the testing.

Pseudo-randomness also gives you repeatability; given a particular
seed, you can generate the same sequence over and over again.  Imagine
the frustration of someone who is trying to debug a subtle timing error
that can't be reproduced because the circumstances can't be set up
that caused the error in the first place...

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: eric dahlman
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <tz4wv8zi7m9.fsf@sibelius.cs.colostate.edu>
Duane Rettig <·····@franz.com> writes:

> eric dahlman <·······@cs.colostate.edu> writes:
> 
> > Lieven Marchand <···@wyrd.be> writes:
> > 
> > > In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> > > above a certain size.
> > > 
> > > USER(8): (random (fac 200))
> > > 
> > > Error: This integer is too large to be converted to a double-float:
> >         [snip big int]
> > >   [condition type: SIMPLE-ERROR]
> > > 
> > > Is this a bug or is this allowed by the standard as an implementation
> > > limitation?
> > 
> > Even if this was just an implementation limitation I think that you
> > should look into getting your randomness from a different source.
> > Pseudo-random number generators like random are notoriously bad when
> > used to generate more that a handful of bits, even the 32 they claim
> > to do in one shot is really tenuous.
> 
> This is not true.  Random numbers larger than 32-bits are easy to
> generate.  And with patches, Allegro CL 6.0 does a good job of this.
> We use the Mersenne Twister Algorithm, which has a large cycle.

I would disagree.  There are lots of ways that random number
generators break down fortunately the authors of the Mersenne Twister
Algorithm have done much of the analysis work for us to quote:

   However, it is widely believed that the spectral test is one of the
   strongest test to select a good generator. MT is designed to pass a
   similar test, called the k-distribution test. For example, if we
   look the output with 32-bit accuracy, then the 623-tuples from the
   output in a whole period are equidistributed in the 623-dimensional
   unit cube. For 16-bit accuracy, 1246-tuples are equidistributed in
   1246-dimension, and for 2-bit accuaracy, in 9968-dimension. These
   values are at least 15 times larger than the previous records. 

I stole that from there web site at
http://www.math.keio.ac.jp/~matumoto/emt.html

This is actually really good, and Franz is right to be tauting the
fact that the use this algorithm in their implementation.  Just for
comparisons the old Fortran rand48 generator would have died at
3-tuples and C's rand function could maybe get to 5.  It has been a
few years since I look at them so I could be off a little but the
point is that they are bad.  On a side note CMUCL also uses this
generator and the Lisp code for their implementation is available on
the above site if anyone wants to look at how it works.[1]

The C and Fortran generators really cannot be any better than they are
since this is really a function of the number of bits used to
represent the random state.  If your random state is 32 bits then you
cannot deterministically use that to generate a pseudo-random object
needing 128 bits there are not enough bits.  Depending on how your
generator cycles you will either constantly regenerate the same subset
as on your first iteration or you will generate a set of cosets one
for each cycle.  The error from the original poster, which I cut out,
indicated that the previous implementation was using what I presume
were 64bit floats for the pseudo-random generator.  This means that
generating any objects which require more than 64 bits is unsound.
Actually, you should not use more than half the number of bits in the
random state but that is a different kettle of fish.

Just for reference the random state in the new generator uses 19936
bits.  You will have the same problems with this as the older versions
as you try to generate objects which around 19936 bits to represent.
This is better than a limit of 32 bits but it is still just as real.
And if you do not think that you would be generating things that large
it happens implicitly all the time.  For instance if you are randomly
traversing a graph you my only use a couple of bits for each local
decision, however, the entire path represents a larger random object.
That was one of the driving forces behind the MT generator since other
generators would fail for Monte Carlo methods.

Finally, I would submit one more reason that even the MT algorithm
would break down for large objects.  If we look at the claims of the
authors, which I have no reason to doubt, they say in so many words
that their generator will generator will generate any 623 tuple of
32bit words.  There are not surprisingly 2^19936 such objects which
happens to be the cycle length of the generator.  This means that once
you have generated one one 19936 bit object you will never generate it
again until the generator has looped.  All that you have in this case
is a permutation of all such objects.  This is certainly not random
since you are guaranteed that there will not be an chance of a repeat
occurrence of an event.  This degradation of randomness is guaranteed
to happen simply because your random number generator is ideally an
automorphism on the set of random states.  So as you approach the size
of you random state things get less random.  You are guaranteed to
loose, the math is against you.

This has gotten much too long as it is so I will stop.  I still am
very opposed to Duane's statement that "Random numbers larger than
32-bits are easy to generate."  Certainly the use of the MT generator
ups the bar for how many bits you can generate it certainly does not
remove the inherent mathematical implications of the way that
pseudo-random numbers are generated.

-Eric

Footnotes: 
[1] Looking at the code I saw one problem with the CMUCL code and that
was that they use a fixnum as their seed.  This is then used to
calculate the larger random state used by the generator.  This means
that they are only 2^32 points from which random numbers can be
generated.  This is significantly smaller than the 2^19936 which
exist, this seeding process can significantly bias the set of numbers
which will be generated.  Ideally, the whole random state would be the
seed, such a chunk of randomness could come from /dev/random under
Linux.
From: Duane Rettig
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <4snjn18bx.fsf@beta.franz.com>
eric dahlman <·······@cs.colostate.edu> writes:

 [...]
>  The error from the original poster, which I cut out,
> indicated that the previous implementation was using what I presume
> were 64bit floats for the pseudo-random generator.

That is correct.

>  This means that
> generating any objects which require more than 64 bits is unsound.
> Actually, you should not use more than half the number of bits in the
> random state but that is a different kettle of fish.

Actually, since a 64-bit float has only 52 real bits of mantissa, and
since we actually truncated them to 48 bits, the real usable bit width
is more like 24.

> Just for reference the random state in the new generator uses 19936
> bits.  You will have the same problems with this as the older versions
> as you try to generate objects which around 19936 bits to represent.
> This is better than a limit of 32 bits but it is still just as real.
 [...]

> This has gotten much too long as it is so I will stop.  I still am
> very opposed to Duane's statement that "Random numbers larger than
> 32-bits are easy to generate."  Certainly the use of the MT generator
> ups the bar for how many bits you can generate it certainly does not
> remove the inherent mathematical implications of the way that
> pseudo-random numbers are generated.

It seems you have 32-bits-on-the-brain.  In Lisp, 32-bits is a meaningless
width, except for performance considerations.  Perhaps you should also
revise your statements for 64-bit architectures.  As for me, I willingly
revise my statement to be more general:

"Random numbers larger than N bits are easy to generate; all you need is
a random-number generator that has at least N*2 bits of state."

This works for the original question: (integer-length (fac 200)) => 1246,
which is well under the 19936 bit MT cycle.

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: eric dahlman
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <tz4bsqbhwib.fsf@sibelius.cs.colostate.edu>
Duane Rettig <·····@franz.com> writes:

> eric dahlman <·······@cs.colostate.edu> writes:
> 
>  [...]
> >  The error from the original poster, which I cut out,
> > indicated that the previous implementation was using what I presume
> > were 64bit floats for the pseudo-random generator.
> 
> That is correct.
> 
> >  This means that
> > generating any objects which require more than 64 bits is unsound.
> > Actually, you should not use more than half the number of bits in the
> > random state but that is a different kettle of fish.
> 
> Actually, since a 64-bit float has only 52 real bits of mantissa, and
> since we actually truncated them to 48 bits, the real usable bit width
> is more like 24.

And just for reference these are the middle-order(is that a word?) bits.

> 
> > Just for reference the random state in the new generator uses 19936
> > bits.  You will have the same problems with this as the older versions
> > as you try to generate objects which around 19936 bits to represent.
> > This is better than a limit of 32 bits but it is still just as real.
>  [...]
> 
> > This has gotten much too long as it is so I will stop.  I still am
> > very opposed to Duane's statement that "Random numbers larger than
> > 32-bits are easy to generate."  Certainly the use of the MT generator
> > ups the bar for how many bits you can generate it certainly does not
> > remove the inherent mathematical implications of the way that
> > pseudo-random numbers are generated.
> 
> It seems you have 32-bits-on-the-brain.  In Lisp, 32-bits is a meaningless
> width, except for performance considerations.  Perhaps you should also
> revise your statements for 64-bit architectures.  As for me, I willingly
> revise my statement to be more general:

I could care less about how many bits there are, that was just
important in the context of other generators described.
Pseudo-randomness was just delivered in 32 bit packages.  It is also
important in the context of MT since the algorithm is defined on an
array of 32 bit integers.  Me personally I could care less about how
many bits there are, I would be really happy with a 1 bit true random
number generator ;-)

> 
> "Random numbers larger than N bits are easy to generate; all you need is
> a random-number generator that has at least N*2 bits of state."
> 
> This works for the original question: (integer-length (fac 200)) => 1246,
> which is well under the 19936 bit MT cycle.

I would agree with that.  The real problem with this bit limit comes
when you are doing something like a Monte Carlo simulation of these
things because all of the bits used in the simulation are part of the
same conceptual object.  So here we could only have 16 steps in a
simulation before the bad mojo starts.  That is assuming that all the
bits are good; as I am inclined to believe after reading their web page.

That said the bad mojo may not be that bad depending on what you are
doing.  One just needs to be aware of what is going on.

-Eric

> 
> -- 
> Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
> 1995 University Ave Suite 275  Berkeley, CA 94704
> Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Raymond Toy
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <4nr8z7i4sk.fsf@rtp.ericsson.se>
>>>>> "eric" == eric dahlman <·······@cs.colostate.edu> writes:

[nice discussion of MT generator snipped]

    eric> Footnotes: 
    eric> [1] Looking at the code I saw one problem with the CMUCL code and that
    eric> was that they use a fixnum as their seed.  This is then used to
    eric> calculate the larger random state used by the generator.  This means
    eric> that they are only 2^32 points from which random numbers can be
    eric> generated.  This is significantly smaller than the 2^19936 which
    eric> exist, this seeding process can significantly bias the set of numbers
    eric> which will be generated.  Ideally, the whole random state would be the
    eric> seed, such a chunk of randomness could come from /dev/random under
    eric> Linux.

It's done this way because that's how the referece C code for the MT
generator seeded the generator.  A seed (the time) is used to seed a
32-bit linear congruential generator.  The output is used to seed the
MT generator.

Using /dev/random would be a good option for the x86 port.

Ray
From: eric dahlman
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <tz47l0zhv6a.fsf@sibelius.cs.colostate.edu>
Raymond Toy <···@rtp.ericsson.se> writes:

> It's done this way because that's how the referece C code for the MT
> generator seeded the generator.  A seed (the time) is used to seed a
> 32-bit linear congruential generator.  The output is used to seed the
> MT generator.

I hadn't looked at the C code but suspected as much.  I went back and
the author's acknowledge this as a problem and describe how to load
the whole state as a fix.

> 
> Using /dev/random would be a good option for the x86 port.

If I can add things to the wish list an interface to convert from
(simple-array (unsigned-byte 32) (627)) to a random state would be
nice in general, since then I could get my seeds from a true random
source somewhere and then load them on any platform. It is not hard to
hack such a thing but it is also nice for these things to be
standardized.

-Eric
From: Duane Rettig
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <466gjasku.fsf@beta.franz.com>
eric dahlman <·······@cs.colostate.edu> writes:
> Raymond Toy <···@rtp.ericsson.se> writes:
> > It's done this way because that's how the referece C code for the MT
> > generator seeded the generator.  A seed (the time) is used to seed a
> > 32-bit linear congruential generator.  The output is used to seed the
> > MT generator.
> 
> I hadn't looked at the C code but suspected as much.  I went back and
> the author's acknowledge this as a problem and describe how to load
> the whole state as a fix.
> 
> > 
> > Using /dev/random would be a good option for the x86 port.
> 
> If I can add things to the wish list an interface to convert from
> (simple-array (unsigned-byte 32) (627)) to a random state would be
> nice in general, since then I could get my seeds from a true random
> source somewhere and then load them on any platform. It is not hard to
> hack such a thing but it is also nice for these things to be
> standardized.

The Ansi spec already requires that random-states be printable readably,
but it makes the actual internals of the state implementation dependent
(so as to allow, for example, for changes when something better than
Mersenne Twister comes along).  Allegro CL complies, and writes the state
out in a way which, if you know what is supposed to be inside, you can
substitute your own data.

This is long (sorry) but it demonstarates printing and reading again to
create a new random-state - if you wanted to you could substitute new
data as well; I just cut and pasted the printed representation for
demo purposes:

CL-USER(1): (progn (print *random-state*) nil)

#S(RANDOM-STATE :MTI 76
                :FIXSEED
                #(3960924350 2165561044 562617442 2270225120 1264129478
                  758582028 172407450 2782512936 595962478 1609675396
                  211021714 2717304176 2094763478 3329110108 91008810
                  3878026008 701479198 3845262388 2283251970 2663711744
                  2914272230 2879280684 1985409402 345983304 3388282382
                  3702670244 2757470834 1611946448 2084174646 733555132
                  470106314 3689324024 2838659326 302298388 2153601698
                  178954272 1819031814 4092620492 1385422938 594561768
                  4199410606 2199270852 397379922 4074037552 1721874838
                  2353290140 3458749930 1101162328 2027262174 3716209140
                  2073340866 2214259392 3462956966 2786415212 1591564474
                  2443238792 2089138126 2948879716 3450356146 1879154960
                  3038475894 327406204 1514525450 748233912 3902183486
                  3215293268 163203298 2398071904 3208776774 3740135308
                  2564323610 1591668648 3777317870 4284672004 1593426450
                  446227952 4310102 824885980 563040682 824296344 1337084062
                  622300852 1153569666 502152064 2848107110 3042049452
                  4108476154 3832186056 1326331790 2985385764 99381234
                  2365611344 2679575222 2446204476 2387323978 658205304
                  837981054 2764741780 1863191074 4031924896 3134517382
                  279169100 4094022618 3198412904 3049539630 3496084548
                  3143525586 3775780528 2980968214 3495008028 3462451050
                  344657624 1150526302 1823022452 1981706562 2182495040
                  172380454 2431610092 3753286970 640370184 3587478606
                  1510967780 776060466 732440976 1081412342 2738710012
                  3214677386 800808504 24562622 2751676372 4279915874 81370080
                  3588719814 1167640588 3998918554 1012446760 2522851694
                  2573746564 2691410578 1539092592 2032272598 1954831708
                  842920490 4068085784 2251937822 2758183732 1246678530
                  4159943424 1141585638 188013868 3915422330 34095688
                  1073321230 380152996 3664273778 1904984784 2532347446
                  1503956156 2475400138 3201411320 1783816702 1772740116
                  4056768418 3526032160 2332305414 3276535756 1035639130
                  1430554088 4011157678 2599502532 543871058 3164386352
                  203335830 2933959836 1672860906 1120704600 3206427102
                  1095427316 3025966274 1408877504 3535125158 3291818860
                  1165309882 1289437320 349369550 3010306148 3154541234
                  3335728144 3940950902 4229598588 4262582282 1915570104
                  288782654 1435834964 3405715426 2220749664 2342829382
                  4055525004 3761999898 386727080 3599173870 1953449220
                  2874709778 540403440 4017872214 3313804764 3669577386
                  337543832 1049930142 4175501236 3402505858 3749100672
                  3714391910 4085102252 2764737018 3449971656 1913746574
                  1026102820 2456417522 4024907856 3547457462 2742089532
                  574625098 424115064 3734204030 1332573076 1376038178
                  991910459 509385971 3537599427 2096754419 3166091099
                  3909534739 2164693475 1536509731 2724691483 4185966419
                  2635589891 1287654643 2656984219 1624805971 2560505987
                  702829987 2419849531 268340723 1252857539 1085575987
                  1044679131 1351385363 3776074979 2833245283 851722651
                  98405459 774732611 3489718643 2238502363 3095603091
                  4165496067 1948336803 745584571 4079479539 1020855491
                  3139128307 3565060699 889947667 3268324963 3972901155
                  1422215835 511657043 3032992771 1249316467 4128902043
                  186423379 410296195 3543326499 3893290555 1634294899
                  2566499651 1055263795 1437987675 1532736147 3914709219
                  1509277027 2657870747 549875411 1850638403 3570888563
                  977553883 4015148435 3335365507 2275769763 2140963899
                  1634453747 3682901443 878380531 578754651 988811027
                  1320535011 4165323299 87401499 1860797779 3868304899
                  4189532403 2933665947 4079780179 2552466563 3272696227
                  3514549051 3173214195 3132251843 3129225011 722057179
                  884675859 703907299 2102040163 3308783259 2140559443
                  4103536451 1534130547 394887899 544543123 794468099
                  3313524387 3632484795 333716467 2871117763 1046679027
                  559259227 2936279059 642307683 566603555 1842328731
                  1335536979 2064285699 1799875187 1898013339 1129362515
                  248675971 3233448739 2710455099 3074699379 3081577795
                  1726650675 3344750427 2082036883 793479907 3306906211
                  525114267 2157984467 2626707779 3856159347 2687822811
                  1357363859 256590723 4217950371 2692787259 1364657395
                  1663226307 3541294835 1653179227 3393312787 2090473443
                  2995224355 231194651 47613779 1598056707 3359167219
                  2347045531 3940335187 3897587331 2069440419 789671227
                  310589939 4172812995 1017357107 2400377307 2878776595
                  1388243171 2333955171 3067918747 2925554771 1066700611
                  3220427635 1360600539 2364081043 488685827 216334499
                  4156067259 3151523571 2112185539 382033907 1343268955
                  1439219219 3809067619 2752588067 520937115 1159659603
                  2330219011 537017459 3352420251 18557011 3033228163
                  2170214691 1931991611 3441480307 1246017347 3117497395
                  799810395 1959438995 2246900451 3484690787 3384761755
                  716106963 1587291203 1194593139 1235421147 1343098259
                  1093461379 4114867619 3511371835 2417377011 1430201795
                  1029902835 223757403 844932883 616716259 4203450915
                  207383579 3421928275 654620163 3369330931 1825563803
                  428745043 269321347 2520074659 3808774459 700419571
                  1678046403 1503990067 67911131 2122759955 1563943395
                  1829632099 4171166363 3556249171 1692686659 1533683059
                  564654811 790562707 2569827587 3114722979 597498299
                  4005661683 2968782787 2606193256 2500144942 14336668
                  4039769162 1698809616 975648166 1690854388 3317917426
                  1045015512 393584094 563219788 3250598426 253741664
                  3329738550 1682007684 2198807714 690635336 3550783118
                  2199242684 2859464682 4045907120 2171061702 501453012
                  2035136530 3306034552 3878775422 3524508460 1208607354
                  70320704 409811734 1637073188 2471928578 2716740008
                  559875694 2621076956 1047697034 1464528976 3076683878
                  928201140 414263730 4043362584 3249282846 963373068
                  3948281818 260918048 3183030902 2475424836 1400809186
                  1919700744 3243616334 986461308 2467681194 3992480880
                  3583529734 40266004 2656654930 2035575096 3814749758
                  3554668652 319023290 3212195968 1849674966 32309860
                  511960514 2203253224 2647338414 187348764 3882380746
                  2946583952 2637382694 3065204852 841487730 2186151256
                  4232558942 701424588 1884165274 1566792416 1339867574
                  2112809732 1470931234 1764572104 779966734 1494285372
                  1286616426 3770869040 4131318598 3142785108 3576909202
                  1497499384 2249421310 1983872684 2193363962 4272425408
                  2645555094 4158720676 106721666 703162920 2846115310
                  1449190748 3137100042 4110617040 364243430 2986432820
                  3587133746 2205094808 3829388190 3568649612 3848396122
                  3708368544 2172871158 3482006980 1186432098 553870728
                  1631975374 329420796 2860887082 1965282288 2993162118
                  3743851412 1958856914 4030819768 343515326 1606684908
                  1868234554 1066175744 2777749078 4073171684 841144130
                  644969832 3875380270 3251555228 2002706762 3554916880
                  1915772582 2309807348 2106917362 3375582936 2342492382
                  3483094092 2055305498 75935072 1097888822 334821764
                  3780381090 3848919368 2383841678 433381564 2816938730
                  636145584 75447494 2178661844 1183026450 648737912
                  1033996158 2655014444 218555258 3530571072 827929110
                  2206456868 3752189442 917199528 953474926 3999938268
                  3084465546 3681293136 3147550054 991210164 795309234
                  3908823576 2884926694)) 
NIL
CL-USER(2): #S(RANDOM-STATE :MTI 76
                :FIXSEED
                #(3960924350 2165561044 562617442 2270225120 1264129478
                  758582028 172407450 2782512936 595962478 1609675396
                  211021714 2717304176 2094763478 3329110108 91008810
                  3878026008 701479198 3845262388 2283251970 2663711744
                  2914272230 2879280684 1985409402 345983304 3388282382
                  3702670244 2757470834 1611946448 2084174646 733555132
                  470106314 3689324024 2838659326 302298388 2153601698
                  178954272 1819031814 4092620492 1385422938 594561768
                  4199410606 2199270852 397379922 4074037552 1721874838
                  2353290140 3458749930 1101162328 2027262174 3716209140
                  2073340866 2214259392 3462956966 2786415212 1591564474
                  2443238792 2089138126 2948879716 3450356146 1879154960
                  3038475894 327406204 1514525450 748233912 3902183486
                  3215293268 163203298 2398071904 3208776774 3740135308
                  2564323610 1591668648 3777317870 4284672004 1593426450
                  446227952 4310102 824885980 563040682 824296344 1337084062
                  622300852 1153569666 502152064 2848107110 3042049452
                  4108476154 3832186056 1326331790 2985385764 99381234
                  2365611344 2679575222 2446204476 2387323978 658205304
                  837981054 2764741780 1863191074 4031924896 3134517382
                  279169100 4094022618 3198412904 3049539630 3496084548
                  3143525586 3775780528 2980968214 3495008028 3462451050
                  344657624 1150526302 1823022452 1981706562 2182495040
                  172380454 2431610092 3753286970 640370184 3587478606
                  1510967780 776060466 732440976 1081412342 2738710012
                  3214677386 800808504 24562622 2751676372 4279915874 81370080
                  3588719814 1167640588 3998918554 1012446760 2522851694
                  2573746564 2691410578 1539092592 2032272598 1954831708
                  842920490 4068085784 2251937822 2758183732 1246678530
                  4159943424 1141585638 188013868 3915422330 34095688
                  1073321230 380152996 3664273778 1904984784 2532347446
                  1503956156 2475400138 3201411320 1783816702 1772740116
                  4056768418 3526032160 2332305414 3276535756 1035639130
                  1430554088 4011157678 2599502532 543871058 3164386352
                  203335830 2933959836 1672860906 1120704600 3206427102
                  1095427316 3025966274 1408877504 3535125158 3291818860
                  1165309882 1289437320 349369550 3010306148 3154541234
                  3335728144 3940950902 4229598588 4262582282 1915570104
                  288782654 1435834964 3405715426 2220749664 2342829382
                  4055525004 3761999898 386727080 3599173870 1953449220
                  2874709778 540403440 4017872214 3313804764 3669577386
                  337543832 1049930142 4175501236 3402505858 3749100672
                  3714391910 4085102252 2764737018 3449971656 1913746574
                  1026102820 2456417522 4024907856 3547457462 2742089532
                  574625098 424115064 3734204030 1332573076 1376038178
                  991910459 509385971 3537599427 2096754419 3166091099
                  3909534739 2164693475 1536509731 2724691483 4185966419
                  2635589891 1287654643 2656984219 1624805971 2560505987
                  702829987 2419849531 268340723 1252857539 1085575987
                  1044679131 1351385363 3776074979 2833245283 851722651
                  98405459 774732611 3489718643 2238502363 3095603091
                  4165496067 1948336803 745584571 4079479539 1020855491
                  3139128307 3565060699 889947667 3268324963 3972901155
                  1422215835 511657043 3032992771 1249316467 4128902043
                  186423379 410296195 3543326499 3893290555 1634294899
                  2566499651 1055263795 1437987675 1532736147 3914709219
                  1509277027 2657870747 549875411 1850638403 3570888563
                  977553883 4015148435 3335365507 2275769763 2140963899
                  1634453747 3682901443 878380531 578754651 988811027
                  1320535011 4165323299 87401499 1860797779 3868304899
                  4189532403 2933665947 4079780179 2552466563 3272696227
                  3514549051 3173214195 3132251843 3129225011 722057179
                  884675859 703907299 2102040163 3308783259 2140559443
                  4103536451 1534130547 394887899 544543123 794468099
                  3313524387 3632484795 333716467 2871117763 1046679027
                  559259227 2936279059 642307683 566603555 1842328731
                  1335536979 2064285699 1799875187 1898013339 1129362515
                  248675971 3233448739 2710455099 3074699379 3081577795
                  1726650675 3344750427 2082036883 793479907 3306906211
                  525114267 2157984467 2626707779 3856159347 2687822811
                  1357363859 256590723 4217950371 2692787259 1364657395
                  1663226307 3541294835 1653179227 3393312787 2090473443
                  2995224355 231194651 47613779 1598056707 3359167219
                  2347045531 3940335187 3897587331 2069440419 789671227
                  310589939 4172812995 1017357107 2400377307 2878776595
                  1388243171 2333955171 3067918747 2925554771 1066700611
                  3220427635 1360600539 2364081043 488685827 216334499
                  4156067259 3151523571 2112185539 382033907 1343268955
                  1439219219 3809067619 2752588067 520937115 1159659603
                  2330219011 537017459 3352420251 18557011 3033228163
                  2170214691 1931991611 3441480307 1246017347 3117497395
                  799810395 1959438995 2246900451 3484690787 3384761755
                  716106963 1587291203 1194593139 1235421147 1343098259
                  1093461379 4114867619 3511371835 2417377011 1430201795
                  1029902835 223757403 844932883 616716259 4203450915
                  207383579 3421928275 654620163 3369330931 1825563803
                  428745043 269321347 2520074659 3808774459 700419571
                  1678046403 1503990067 67911131 2122759955 1563943395
                  1829632099 4171166363 3556249171 1692686659 1533683059
                  564654811 790562707 2569827587 3114722979 597498299
                  4005661683 2968782787 2606193256 2500144942 14336668
                  4039769162 1698809616 975648166 1690854388 3317917426
                  1045015512 393584094 563219788 3250598426 253741664
                  3329738550 1682007684 2198807714 690635336 3550783118
                  2199242684 2859464682 4045907120 2171061702 501453012
                  2035136530 3306034552 3878775422 3524508460 1208607354
                  70320704 409811734 1637073188 2471928578 2716740008
                  559875694 2621076956 1047697034 1464528976 3076683878
                  928201140 414263730 4043362584 3249282846 963373068
                  3948281818 260918048 3183030902 2475424836 1400809186
                  1919700744 3243616334 986461308 2467681194 3992480880
                  3583529734 40266004 2656654930 2035575096 3814749758
                  3554668652 319023290 3212195968 1849674966 32309860
                  511960514 2203253224 2647338414 187348764 3882380746
                  2946583952 2637382694 3065204852 841487730 2186151256
                  4232558942 701424588 1884165274 1566792416 1339867574
                  2112809732 1470931234 1764572104 779966734 1494285372
                  1286616426 3770869040 4131318598 3142785108 3576909202
                  1497499384 2249421310 1983872684 2193363962 4272425408
                  2645555094 4158720676 106721666 703162920 2846115310
                  1449190748 3137100042 4110617040 364243430 2986432820
                  3587133746 2205094808 3829388190 3568649612 3848396122
                  3708368544 2172871158 3482006980 1186432098 553870728
                  1631975374 329420796 2860887082 1965282288 2993162118
                  3743851412 1958856914 4030819768 343515326 1606684908
                  1868234554 1066175744 2777749078 4073171684 841144130
                  644969832 3875380270 3251555228 2002706762 3554916880
                  1915772582 2309807348 2106917362 3375582936 2342492382
                  3483094092 2055305498 75935072 1097888822 334821764
                  3780381090 3848919368 2383841678 433381564 2816938730
                  636145584 75447494 2178661844 1183026450 648737912
                  1033996158 2655014444 218555258 3530571072 827929110
                  2206456868 3752189442 917199528 953474926 3999938268
                  3084465546 3681293136 3147550054 991210164 795309234
                  3908823576 2884926694))
#S(RANDOM-STATE :MTI 76
                :FIXSEED
                #(3960924350 2165561044 562617442 2270225120 1264129478
                  758582028 172407450 2782512936 595962478 1609675396 ...))
CL-USER(3): (random-state-p *)
T
CL-USER(4): (eq ** *random-state*)
NIL
CL-USER(5): 


-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: eric dahlman
Subject: Test Methodology (was Re: RANDOM with bignum argument)
Date: 
Message-ID: <tz4ofubhzm6.fsf_-_@sibelius.cs.colostate.edu>
Duane Rettig <·····@franz.com> writes:

> eric dahlman <·······@cs.colostate.edu> writes:
[snip: answered in other thread]
> >  In general if you start asking
> > for bigger chunks like the amount you would need for (random (fac
> > 200)) you need a real source of randomness.  Check out
> > www.lavarand.com for a system out of SGI for doing this.
> 
> True randomness is not always desirable.  One of the problems with
> true randomness is that at a local level, coincidence can make the
> generator look downright repetitive.  And when you have to test
> softare or hardware, sometimes it is not randomness you want but
> relatively even distribution, which gives you a higher confidence of
> coverage in the testing.


If you want coverage testing then do just that don't use random test
cases or worse yet biased random test cases like you suggest.  Random
testing is a very useful and statistically justified method for
evaluating software but it is not about throwing a bunch of garbage at
the thing and seeing what will stick.  It is no silver bullet, you
still need to understand the domain and implementation you are testing
in order to identify meaningful random tests.  You also do not need to
allow for repetition in your tests, just select unique tests.  If you
cannot generate a sufficient number of distinct test that should be a
hint that this is not the time for randomized testing.

I disagree that using stuff-that-people-think-looks-random-but-ain't
provides a higher confidence in testing.  It sets off clanging bells
with bright blinking lights in my mind.  You have introduced a bias
into the testing with no justification or correlation to either the
implementation or the domain.  That said using a biased random
generation scheme may be very well justified, but it has to be
justified.  For instance

        * Our domain contains 23 different classes of input we need to
          sample from each.

        * We know all of the boundary conditions occur in this region
          of the space, bias the tests to fall in this region.

        * We have created Markov models of the input under these
          different conditions.  Stress test the implementation under
          each.

Random testing is no substitute for coverage testing or partition
testing.  I personally would be much happier with a statistically
verifiable statement about the probability that a error will be
encountered and that the program will correctly process some given
input. You can make these statements based on the way you sample the
input domain if you have a good random test generator, when you just
fiddle with things you cannot say anything beyond "Well, Zeke tried it
a jillion times and it didn't break." [1]

> Pseudo-randomness also gives you repeatability; given a particular
> seed, you can generate the same sequence over and over again.
> Imagine the frustration of someone who is trying to debug a subtle
> timing error that can't be reproduced because the circumstances
> can't be set up that caused the error in the first place...

Then use the pseudo-random generator for debugging or write your
random numbers to storage so that you can "play them back" when
debugging.  There are may randomized algorithms like simulated
annealing, genetic algorithms, randomized SAT solvers which are
mathematically guaranteed to converge to a solution or to have a
certain well defined distribution of approximations which do not
converge in practice.  This is because of unwanted interaction with
the pseudo-random number generator, change or replace the generator
and your results change.  Hook it up to a real entropy source and
magically it works the way the math predicts.  This is an even worse
bug since everything is correct, it just doesn't work.

My point is that many things depend on randomness to operate and when
you hook a complex system up to a pseudo-random number generator it is
quite common for disfunctional behavior to emerge.  

-Eric

> 
> -- 
> Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
> 1995 University Ave Suite 275  Berkeley, CA 94704
> Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)

Footnotes: 

[1] I have to confess when hacking on things I have been known to pipe
lots of junk through the code to see where things break.  But it is
nothing more than the fact that I cannot be bothered to figure out
what I really should test.  This catches lots of bugs but I would
never try to sell that to a customer as a valid testing strategy.
From: Reini Urban
Subject: Re: Test Methodology (was Re: RANDOM with bignum argument)
Date: 
Message-ID: <3ad2b535.68067776@judy>
eric dahlman wrote:
....
>-Eric

isn't that a trademark?
-- 
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
From: eric dahlman
Subject: Re: Test Methodology (was Re: RANDOM with bignum argument)
Date: 
Message-ID: <tz4k84swxez.fsf@sibelius.cs.colostate.edu>
······@sbox.tu-graz.ac.at (Reini Urban) writes:

> eric dahlman wrote:
> ....
> >-Eric
> 
> isn't that a trademark?

I think that only the reader macro versions are trademarked.
;-)

-Eric 
From: Lieven Marchand
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <m366gjl2lq.fsf@localhost.localdomain>
 eric dahlman <·······@cs.colostate.edu> writes:

> Lieven Marchand <···@wyrd.be> writes:
> 
> > In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> > above a certain size.
> > 
> > USER(8): (random (fac 200))
> > 
> > Error: This integer is too large to be converted to a double-float:
>         [snip big int]
> >   [condition type: SIMPLE-ERROR]
> > 
> > Is this a bug or is this allowed by the standard as an implementation
> > limitation?
> 
> Even if this was just an implementation limitation I think that you
> should look into getting your randomness from a different source.
> Pseudo-random number generators like random are notoriously bad when
> used to generate more that a handful of bits, even the 32 they claim
> to do in one shot is really tenuous.  In general if you start asking
> for bigger chunks like the amount you would need for (random (fac
> 200)) you need a real source of randomness.  Check out
> www.lavarand.com for a system out of SGI for doing this.

The randomness isn't very important for the application. I'm
generating a fixed number of bases for Fermat tests in a probabilistic
primality test. So an easy work around for the problem was generating
random bases below the limit ACL has problems with in stead of the
total range of [2, possible-prime-number].

-- 
Lieven Marchand <···@wyrd.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: Jochen Schmidt
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <9aj6ap$58ofu$1@ID-22205.news.dfncis.de>
Lieven Marchand wrote:

> The randomness isn't very important for the application. I'm
> generating a fixed number of bases for Fermat tests in a probabilistic
> primality test. So an easy work around for the problem was generating
> random bases below the limit ACL has problems with in stead of the
> total range of [2, possible-prime-number].

Why not a Miller-Rabin Test? Its safer than Fermat and faster than 
Solovay-Strassen...

Here is my implementation. I open for hints to make it faster.

;;; Fast  (mod (expt number exponent) modulus)
(defun expt-mod (number exponent modulus)
  (loop :with result = 1
        :for exp = exponent :then (floor exp 2)
        :for sqr = number :then (mod (* sqr sqr) modulus)
        :until (zerop exp)
        :when (oddp exp)
        :do (setf result (mod (* result sqr) modulus))
        :finally (return result)))

(defparameter *primeset*
  (coerce (make-array 302
                      :element-type 'fixnum
                      :initial-contents
                      '(3 5 7 11 13 17 19 23 29 31 37 41
                        43 47 53 59 61 67 71 73 79 83 89 97 101 103
                        107 109 113 127 131 137 139 149 151 157 163
                        167 173 179 181 191 193 197 199 211 223 227
                        229 233 239 241 251 257 263 269 271 277 281
                        283 293 307 311 313 317 331 337 347 349 353
                        359 367 373 379 383 389 397 401 409 419 421
                        431 433 439 443 449 457 461 463 467 479 487
                        491 499 503 509 521 523 541 547 557 563 569
                        571 577 587 593 599 601 607 613 617 619 631
                        641 643 647 653 659 661 673 677 683 691 701
                        709 719 727 733 739 743 751 757 761 769 773
                        787 797 809 811 821 823 827 829 839 853 857
                        859 863 877 881 883 887 907 911 919 929 937
                        941 947 953 967 971 977 983 991 997 1009 1013
                        1019 1021 1031 1033 1039 1049 1051 1061 1063
                        1069 1087 1091 1093 1097 1103 1109 1117 1123
                        1129 1151 1153 1163 1171 1181 1187 1193 1201
                        1213 1217 1223 1229 1231 1237 1249 1259 1277
                        1279 1283 1289 1291 1297 1301 1303 1307 1319
                        1321 1327 1361 1367 1373 1381 1399 1409 1423
                        1427 1429 1433 1439 1447 1451 1453 1459 1471
                        1481 1483 1487 1489 1493 1499 1511 1523 1531
                        1543 1549 1553 1559 1567 1571 1579 1583 1597
                        1601 1607 1609 1613 1619 1621 1627 1637 1657
                        1663 1667 1669 1693 1697 1699 1709 1721 1723
                        1733 1741 1747 1753 1759 1777 1783 1787 1789
                        1801 1811 1823 1831 1847 1861 1867 1871 1873
                        1877 1879 1889 1901 1907 1913 1931 1933 1949
                        1951 1973 1979 1987 1993 1997 1999))
          '(simple-array fixnum (302))))

;;;Test if n is a prime
(defun primep (n &key (trials 15))
    (let ((+n (abs n)))
      (cond ((< +n 2) nil)
            ((= +n 2) t)
            ((= +n 3) t)
            ((and (> +n 1999)
                  (not-primep +n)) nil)
            (t (multiple-value-bind (r s) (%calc-r-s +n)
                 (loop repeat trials
                   for a of-type integer = (+ (random (- +n 3)) 2)
                   never (not (%miller-rabin-test +n a r s))))))))

;;; Cheap primetest by dividing n with all primes in *primeset*
(defun not-primep (n)
  (declare (type (simple-array fixnum (*)) *primeset*))
  (loop :for prime :of-type fixnum :across *primeset*
        :thereis (zerop (mod n prime))))

;;; Calculate r and s so that: n-1 = 2^s * r | r is oddp
(defun %calc-r-s (n)
  (loop :with n-1 of-type integer = (1- n)
    :for s of-type fixnum :upfrom 0
    :until (logbitp s n-1)
    :finally (return (values (ash n-1 (- s)) s))))

;;; Return nil if n is a component number and t if it is (probably) a prime
(defun %miller-rabin-test (n a r s)
  (let ((y (expt-mod a r n))
        (n-1 (1- n)))
    (if (and (/= y 1)
             (/= y n-1))
        (loop :for j of-type fixnum :upfrom 1
              :while (and (<= j (1- s))
                      (/= y  n-1))
              :do (setf y (mod (* y y) n))
              :never (= y 1)
              :finally (return (= y n-1)))
      t))) 

Regards,
Jochen
From: Lieven Marchand
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <m3hf02q9ms.fsf@localhost.localdomain>
Jochen Schmidt <···@dataheaven.de> writes:

> Lieven Marchand wrote:
> 
> > The randomness isn't very important for the application. I'm
> > generating a fixed number of bases for Fermat tests in a probabilistic
> > primality test. So an easy work around for the problem was generating
> > random bases below the limit ACL has problems with in stead of the
> > total range of [2, possible-prime-number].
> 
> Why not a Miller-Rabin Test? Its safer than Fermat and faster than 
> Solovay-Strassen...

Thanks for the code. I needed a primality test for a little run once
program to do with a puzzle in a magazine and I could remember fermat
without my books which I didn't have at hand but not the more advanced
methods.

I know Solovay-Strassen as a multiplication algorithm. What's their
primality test?

-- 
Lieven Marchand <···@wyrd.be>
Gla�r ok reifr skyli gumna hverr, unz sinn b��r bana.
From: Kent M Pitman
Subject: Re: RANDOM with bignum argument
Date: 
Message-ID: <sfwvgok1mgt.fsf@world.std.com>
Lieven Marchand <···@wyrd.be> writes:

> 
> In ACL 5.0 the RANDOM function doesn't work with bignum arguments
> above a certain size.
> 
> USER(8): (random (fac 200))
> 
> Error: This integer is too large to be converted to a double-float:
>        788657867364790503552363213932185062295135977687173263294742
> 5332443594499634033429203042840119846239041772121389196388302576427902426371050
> 6192662495282993111346285727076331723739698894392244562145166424025403329186413
> 1227428294853277524242407573903240321257405579568660226031904170324062351700858
> 796178922222789623703897374720000000000000000000000000000000000000000000000000
>   [condition type: SIMPLE-ERROR]
> 
> Is this a bug or is this allowed by the standard as an implementation
> limitation?

Maybe because I never played with implementing random numbers and I
have no first-hand knowledge of how computationally expensive this
would be, but I don't really see a problem with an implementation
having a limitation of this kind.  I don't know whether the standard
explicitly permits it, but the standard does permit implementations to
have capacity restricctions.

HOWEVER, I do think it should not signal ERROR but rather
SERIOUS-CONDITION (similar to the way STORAGE-CONDITION works) since
it's not documented to be an error.

Then again, this is just my personal opinion and not an offical judgment.
There is no agency that can judge implementational right-or-wrong; we leave
it to the marketplace to vote with their feet.