Re: Anyone need a random number generator?
Rick Fochtman <[email protected]>
| Newsgroups | gmane.comp.emulators.turnkey-mvs |
|---|---|
| Message-ID | <[email protected]> |
-----------------------------------<Another snip>--------------------------------------- > > > On Wed, Apr 28, 2010 at 4:12 PM, Rick Fochtman <[email protected] > <mailto:rfochtman%40ync.net>> wrote: > > > > On Wed, Apr 28, 2010 at 3:03 PM, Ron Hudson <[email protected] > <mailto:hudson.ra%40gmail.com>> wrote: > > > > > > On Wed, Apr 28, 2010 at 12:39 PM, Rick Fochtman <[email protected] > <mailto:rfochtman%40ync.net>> wrote: > > <<deleted>> > > >> //FORT.SYSIN DD * > > >> C RANDOM NUMBER GENERATOR > > >> FUNCTION IRND(ISEED) > > >> IY = IABS(MOD(1103515245 * ISEED + 12345,2**15)) > > >> IRND = IY > > >> RETURN > > >> END > > <<deleted>> > > >> > > >> (Given the math I see there, you might experience integer > overflow conditions in the first argument to the MOD function.) > > > > > > What can I do? I guess I need to user a 'larger' integer - What > is a good reference (there is a short overview > > > on Jay Moseley's site but no detail like how to specify more bits... > > > > > The assembler equivalent should run (i.e. not overflow the registers), > > not sure about how this particular compiler creates the machine > > instructions. You will need to test by calling the routine and > > logging the results. > > > > > ------------------------------------<unsnip>---------------------------------- > > Doing it in Assembler will not "use more bits". FORTH uses the full > 32 bits of the 370 architecture. Since the value 1,103,515,245 is > being multiplied by the ISEED parameter, the resultant value may > easily exceed 32 bits. Perhaps even exceeding the 64 bits result of > the multiply instruction. Then what? > > > > Rick > Correct. S/370 M or MR multiplies two signed 32 bit operands and > places the result in a odd-even pair of 32 bit registers. The result > cannot exceed 64 bits. 7FFFFFFF * 7FFFFFFF will fit. > Then the S/370 D or DR diviides an odd-even pair of 32 bit registers > by the 2**15 result and could result in an overflow condition. Since > he is desiring the MOD result, losing the high order bits of the > result is of no consequence. > --------------------------------<end of "Another snip">-------------------------- That's true, with respect to the basic arithmetic. But the FORTRAN error handler might not see it that way. :-) Rick