home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / game / wb / Klotz.lha / Klotz / src / RandUtils.asm < prev    next >
Assembly Source File  |  1998-02-18  |  2KB  |  118 lines

  1. ;
  2. ; $VER: RandUtils.asm    0.13 (5.1.97) SAS-multiplikativer Kongruenzgenerator
  3. ;            0.12 ( 20.9.93 )
  4. ;
  5.  
  6.  bloc RSeed,8
  7.  
  8. Randomize
  9. *
  10. * Setze Zufallssaat mit Uhr
  11. *
  12.     push    a0-a2/a6/d0-d1
  13.     lea     RSeed(a4),a0
  14.     lea     4(a0),a1
  15.     move.l  a0,a2
  16.     CINT    CurrentTime
  17.     move.l  4(a2),d0
  18.  
  19.     IFD     RNDBG
  20.     move.l  d0,-(sp)
  21.     bsr     LongOut
  22.     ENDC
  23.  
  24.     swap    d0
  25.     add.l   d0,(a2)          Sekunden plus Micros
  26.     pop     a0-a2/a6/d0-d1
  27.     rts
  28. *   Auch eine Art, etwas auszudokumentieren
  29.     IFNE  0
  30.  
  31. FastRand
  32. * ( aus c.lib)
  33. *
  34. *   <=    d0.l:    (pseudo-)Zufallszahl
  35. *  !!! Von wegen Zufallszahl ... Absolut unbrauchbar !!!
  36. *   Na ja ... schon besser
  37.     push    a6
  38.     CGFX    VBeamPos
  39.     move.l  d0,d1
  40.     lea     RSeed(a4),a0        [plus (0 .. 511)]
  41.     move.l  (a0),d0
  42.     rol.l   #1,d0        Mal sehn...
  43.     bhi     .noexor
  44.     eori.l  #$1d872b41,d0
  45. .noexor
  46.     swap    d0
  47.     add.w   d1,d0
  48.     move.l  d0,(a0)
  49.     pop     a6
  50.     rts
  51.     ENDC
  52. Random
  53. *
  54. * Andere Zufallszahlen
  55. *
  56. *   <= d0.l Zufallszahl aus [0 .. 999999]
  57.     push    d1-d3
  58.     copy.l  RSeed,d0
  59.     move.l  d0,d2
  60.     moveq   #98,d1
  61.     bsr     LMul
  62.     move.l  #10000,d1
  63.     bsr     LMod
  64.     moveq   #100,d1
  65.     bsr     LMul
  66.     move.l  d0,d3
  67.     move.l  d2,d0
  68.     moveq   #21,d1
  69.     bsr     LMul
  70.     add.l   d3,d0
  71.     addi.l  #211327,d0
  72.     move.l  #1000000,d1
  73.     bsr     LMod
  74.     reloc.l d0,RSeed
  75.     pop     d1-d3
  76.     rts
  77.     ifne 0
  78. Random2
  79.     push    a0/d1
  80.     copy.l  RSeed,d0
  81.     bpl     .noneg
  82.     neg.l   d0
  83.     add.l   #1,d0
  84. .noneg
  85.     move.l  #397204094,d1
  86.     copy.l  UtlBase,a0
  87.     CALLx   UMult64
  88.     add.l   d1,d1
  89.     tst.l   d0
  90.     bpl     .skip
  91.     addq.l  #1,d1
  92.     bclr    #31,d0
  93. .skip
  94.     add.l   d1,d0
  95.     bpl     .skip2
  96.     addq.l  #1,d0
  97.     bclr    #31,d0
  98. .skip2
  99.     reloc.l d0,RSeed
  100.     pop     a0/d1
  101.     rts
  102.     endc
  103. RangeRand
  104. *   Zufallszahl aus Bereich
  105. *   =>    d0  :    Wert
  106. *   <=    d0  :    ( 0 .. Wert )
  107. ; Na das sieht schon besser aus
  108.     push    d1-d2
  109.     move.l  d0,d2
  110.     addq.l  #1,d2        Range+1
  111.     bsr     Random
  112.     addq.l  #1,d0
  113.     move.l  d2,d1
  114.     bsr     LMod        Rest bei Div durch Range+1, also [0..Range]
  115.     pop     d1-d2
  116.     rts
  117.  
  118.