ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

¦Û¤v¼g ¦Û¤vªº¤è¦¡²£¥Í¶Ã¼Æ

¦Û¤v¼g ¦Û¤vªº¤è¦¡²£¥Í¶Ã¼Æ

¤@¬íÄÁ¡A¥i¥H°õ¦æ·þ¤Ö­Ó ®aªkªº¹Bºâ¡H

¤@¬íÄÁ¡A¥i¥H²£¥Í¦h¤Ö­Ó¶Ã¼Æ¡H

À\²q¬Ý
¤Ñ¤U¬°¤½

¦^´_  stillfish00
¹ê´ú«á¤´¤£º¡·N¡A©I¥sm¦¸«á¡A¤£·|¦^¨ì²Ä¤@²Õ²£¥ÍªºÀH¾÷¼Æ¡A
¥D¦]¬O tmp = a * seed +c  ...
stillfish00 µoªí©ó 2013-11-1 08:16


«á¨Ó§ï¬° tmp = (a mod m) *( seed mod m) + c §Y¥i¡A
²£¥Í¤§¼Ò¼Æ¤£ÅÜ¡A¤S¦]m = 2^24®É¡A tmp¬°¤p©ó2^49¤§¾ã¼Æ¡A
double¤§ºë½T«×¥i§¹¾ãªí¥Ü¡A¤£·|¦³»~®t¡C
#16 ´ú¸Õ¤]¥i¥¿±`´`Àô¡C

TOP

¦^´_ 19# sjgau


    http://www.csie.ntu.edu.tw/train/teacher_display.php?num=18
§Ú¦b ¥x¤j£¾§c ½Òµ{¤¶²Ðºô­¶
¤Ñ¤U¬°¤½

TOP

¦^´_ 18# sunnyso


    11/8 ¦^°ê
³o¨â¤Ñ¡A¦b¥x¤j¦³±Â½Òªº ¦æµ{
»Ý­n ©ú¤Ñ ¤~¯à ¶}©l
¤Ñ¤U¬°¤½

TOP

¦^´_ 10# sjgau

¤£ª¾¤j¤jªº¤é¥»¤§®È¦p¦ó¡H

¦³ªÅ ³Â·Ð«ü¾É³o­Ó¶Ã¼Æ

ÁÂÁÂ
ss

TOP

¤ñ¸û¦nªº ¶Ã¼Æ²£¥Í¾¹ªº ±ø¥ó
¤@ ²£¥Íªº­pºâ³t«× ¶V§Ö¶V¦n

¤G ¶Ã¼Æªº½d³ò©M ­Ó¼Æ¡A¶V¤j¶V¦n


¤T ºÉ¥i¯àªº ±µªñ§¡¤Ã¤À°t

¥| ¦b²£¥Í¤U¤@­Ó ¬Û¦Pªº¶Ã¼Æ¤§«e¡A­n§â©Ò¦³ªº¶Ã¼Æ³£¶]¹L¤@¹M


¤­ ´`Àôªº¶g´Á­n ©T©w

¤» ´`Àôªº ¶g´Á­n ¶V¤j ¶V¦n
¤Ñ¤U¬°¤½

TOP

¦^´_ 15# c_c_lai
¨ä¹ê§Úªº·N«ä¬O³o¼Ë¡G
  1. Sub EX()
  2.   Dim a As Single, b As Single
  3.   Dim i
  4.   
  5.   a = Rnd
  6.   For i = 2 To 16777216
  7.     Rnd
  8.   Next
  9.   b = Rnd
  10.   Debug.Print a, b
  11.   
  12.   a = myRnd
  13.   For i = 2 To 16777216
  14.     myRnd
  15.   Next
  16.   b = myRnd
  17.   Debug.Print a, b
  18.   
  19. End Sub
½Æ»s¥N½X
¹³rnd¤@¼Ë¡A³om¦¸¨úªº¶Ã¼Æ³£·|¤£¤@¼Ë¡A
¦ýrnd¨ú§¹m¦¸«á¡A¦A¨ú¤U¤@¦¸®É¡A·|¦^¨ì²Ä¤@¦¸¨úªº­È¡A¦A¤@¦¸´`Àô¡C
´N¹³LCG¸Ì­±´£¨ìªº¥Í©R¶g´Á

TOP

¦^´_ 14# stillfish00
³o¬O§Ú´ú¸Õªºµ²ªG¡G
A.  rng = myRnd(sngVal)

B.  rng = myRnd(sngVal, 2 ^ 32)

²¤¥[¼W­×³¡¤À¡G
  1. Option Explicit

  2. Sub Ex()
  3.     Dim sngVal As Single, rng As Range, xi As Long
  4.    
  5.     With Sheets(1)
  6.         .Cells.Clear
  7.         
  8.         For xi = 1 To 5
  9.             Set rng = .Range(Chr(64 + xi) & "1")
  10.             For sngVal = 1 To 20
  11.                 '  rng = myRnd(sngVal)
  12.                 rng = myRnd(sngVal, 2 ^ 32)
  13.                 Set rng = rng.Offset(1)
  14.             Next sngVal
  15.         Next xi
  16.         .Columns.AutoFit
  17.     End With
  18. End Sub

  19. Function myRnd(Optional Number, Optional m As Double = 2 ^ 24) As Single
  20.     Dim tmp As Double
  21.     '  LCG Algorithm¡G
  22.     '      X(n+1) = (a * X(n) + c) mod m
  23.     Const a As Long = 1140671485
  24.     Const c As Long = 12820163
  25.     '  Const m As Long = 16777216    '  2^24
  26.     Const x0 As Long = 1         '  ®Ú¾Ú§A¨Ï¥Î­þ²Õ°Ñ¼Æ¡Ax0¦³®É¦³»Ý­n²Å¦Xªº±ø¥ó¡C
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2013-11-1 08:20 ½s¿è

¦^´_ 13# stillfish00
¹ê´ú«á¤´¤£º¡·N¡A©I¥sm¦¸«á¡A¤£·|¦^¨ì²Ä¤@²Õ²£¥ÍªºÀH¾÷¼Æ¡A
¥D¦]¬O tmp = a * seed + c §Y«K¬O double ¼Æ¤´¦s¦³ºë½T«×»~®t...   

LongLong¤S¥u¦³¦b64¦ì¤¸¥­¥x¤W¥i¥H¨Ï¥Î

TOP

¦^´_ 8# sjgau
¦Û¤v¼g¯uªº¥i¥Hµo²{«Ü¦h°ÝÃD¡A¾Ç¨ì«Ü¦h¡A
§Æ±æ¯à©ß¿j¤Þ¥É¡A§Ú¬O±Ä¥ÎMicrosoft Visual Basic ªº¨º²Õ°Ñ¼Æ¡A¥é³yrnd¨ç¼Æ¤@¼Ë¶Ç¦^single¡C
  1. Function myRnd(Optional Number) As Single
  2.   Dim tmp As Double
  3.   'LCG Algorithm¡G
  4.   '  X(n+1) = (a * X(n) + c) mod m
  5.   Const a As Long = 1140671485
  6.   Const c As Long = 12820163
  7.   Const m As Long = 16777216  '2^24
  8.   Const x0 As Long = 1     '®Ú¾Ú§A¨Ï¥Î­þ²Õ°Ñ¼Æ¡Ax0¦³®É¦³»Ý­n²Å¦Xªº±ø¥ó¡C
  9.   
  10.   Static seed As Variant
  11.   '§Q¥ÎIsEmpty§PÂ_¡A¨Óªì©l¤Æ¤@ staticÅܼƬ°«D¹s­È¡C
  12.   If IsEmpty(seed) Then seed = x0
  13.   
  14.   '§Q¥ÎIsMissing§PÂ_ optional °Ñ¼Æ¬O§_¶Ç¤J¡A­Y¨ç¼Æ¦³¶Ç¤J°Ñ¼Æ®É¡A³]¬°ºØ¤l¡C
  15.   If Not IsMissing(Number) Then seed = Number
  16.    
  17.   'myRnd = (a * seed + c) Mod m
  18.   '(a * seed + c)¹L¤j®É¡Amod ·|µo¥Í·¸¦ì¡A¥u¯à¥Î¨ä¥L¤èªk¨D¡C
  19.   
  20.   tmp = a * seed + c  'double
  21.   seed = tmp - m * Fix(tmp / m)   '§Y­pºâ (a * seed + c) Mod m¡A¦¹¬°²£¥Íªº¶Ã¼Æ­È¡A¨Ã³]¬°¤U¦¸ºØ¤l
  22.   myRnd = seed / m  '¨Ï¶Ç¦^¶Ã¼Æ­È¤¶©ó0¨ì1¤§¶¡
  23. End Function
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¤Hªº§Ö¼Ö¡D¤£¬O¦]¬°¥L¾Ö¦³±o¦h¡A¦Ó¬O¦]¬°¥L­p¸û±o¤Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD