www.digitalmars.com         C & C++   DMDScript  

D - My first D project: Mersenne Twister

reply "Andrew Edwards" <edwardsac spamfreeusa.com> writes:
Gentlemen, (Are there any ladies here?)

I've successfully compiled the Mersenne Twister RNG in D.  In it's current
state, it is simply a C program modified to compile in D. I would like to
make it a true "D" program and would appreciate some suggestions on how to
improve upon it! As pointed out by the original authors
(http://www.math.keio.ac.jp/matumoto/emt.html), MT is "NOT SECURE for
CRYPTOGRAPHY", I would like to remedy this situation and eventually provide
an OO version of the RNG.

All guidance and suggestions will be greatly appreciated.
Code is attached.

Andrew


begin 666 mt.d
M+RH #0H ("!-5"YD#0H ("!-97)S96YN92!4=VES=&5R(')A;F1O;2!N=6UB
M97( 9V5N97)A=&]R("TM($0-"B  ($)A<V5D(&]N(&-O9&4 8GD 36%K;W1O
M($UA='-U;6]T;RP 5&%K=6II($YI<VAI;75R82P 4VAA=VX 0V]K=7,L#0H 
M("  ($UA='1H92!"96QL97<L(&%N9"!)<V%K=2!7861A#0H ("!!;F1R97< 
M0RX 161W87)D<R  =C N,2  ,S  4V5P=&5M8F5R(#(P,#, (&5D=V%R9'-A
M8T!I965E+F]R9PT*#0H ("!"969O<F4 =7-I;F<L(&EN:71I86QI>F4 =&AE
M('-T871E(&)Y('5S:6YG(&EN:71?9V5N<F%N9"AS965D*2 -"B  (&]R(&EN
M:71?8GE?87)R87DH:6YI=%]K97DL(&ME>5]L96YG=& I+ T*#0H ("!#;W!Y
M<FEG:'0 *$,I(#$Y.3< +2 R,# R+"!-86MO=&\ 36%T<W5M;W1O(&%N9"!4
M86MU:FD 3FES:&EM=7)A+ T*("  0V]P>7)I9VAT("A#*2 R,# S+"!!;F1R
M97< 0RX 161W87)D<PT*("  06QL(')I9VAT<R!R97-E<G9E9"X-" T*("  
M4F5D:7-T<FEB=71I;VX 86YD('5S92!I;B!S;W5R8V4 86YD(&)I;F%R>2!F
M;W)M<RP =VET:"!O<B!W:71H;W5T#0H ("!M;V1I9FEC871I;VXL(&%R92!P
M97)M:71T960 <')O=FED960 =&AA="!T:&4 9F]L;&]W:6YG(&-O;F1I=&EO
M;G,-"B  (&%R92!M970Z#0H-"B  ("  ,2X 4F5D:7-T<FEB=71I;VYS(&]F
M('-O=7)C92!C;V1E(&UU<W0 <F5T86EN('1H92!A8F]V92!C;W!Y<FEG:'0-
M"B  ("  ("  ;F]T:6-E+"!T:&ES(&QI<W0 ;V8 8V]N9&ET:6]N<R!A;F0 
M=&AE(&9O;&QO=VEN9R!D:7-C;&%I;65R+ T*#0H ("  (#(N(%)E9&ES=')I
M8G5T:6]N<R!I;B!B:6YA<GD 9F]R;2!M=7-T(')E<')O9'5C92!T:&4 86)O
M=F4 8V]P>7)I9VAT#0H ("  ("  (&YO=&EC92P =&AI<R!L:7-T(&]F(&-O
M;F1I=&EO;G, 86YD('1H92!F;VQL;W=I;F< 9&ES8VQA:6UE<B!I;B!T:&4-
M"B  ("  ("  9&]C=6UE;G1A=&EO;B!A;F0O;W( ;W1H97( ;6%T97)I86QS
M('!R;W9I9&5D('=I=&  =&AE(&1I<W1R:6)U=&EO;BX-" T*("  (" S+B!4
M:&4 ;F%M97, ;V8 :71S(&-O;G1R:6)U=&]R<R!M87D ;F]T(&)E('5S960 
M=&\ 96YD;W)S92!O<B!P<F]M;W1E( T*("  ("  ("!P<F]D=6-T<R!D97)I
M=F5D(&9R;VT =&AI<R!S;V9T=V%R92!W:71H;W5T('-P96-I9FEC('!R:6]R
M('=R:71T96X #0H ("  ("  ('!E<FUI<W-I;VXN#0H-"B  (%1(25, 4T]&
M5%=!4D4 25, 4%)/5DE$140 0ED 5$A%($-/4%E224=(5"!(3TQ$15)3($%.
M1"!#3TY44DE"551/4E,-"B  (")!4R!)4R( 04Y$($%.62!%6%!215-3($]2
M($E-4$Q)140 5T%24D%.5$E%4RP 24Y#3%5$24Y'+"!"550 3D]4#0H ("!,
M24U)5$5$(%1/+"!42$4 24U03$E%1"!705)204Y42453($]&($U%4D-(04Y4
M04))3$E462!!3D0 1DE43D534R!&3U(-"B  ($$ 4$%25$E#54Q!4B!055)0
M3U-%($%212!$25-#3$%)345$+B  24X 3D\ 159%3E0 4TA!3$P 5$A%($-/
M4%E224=(5"!/5TY%4B!/4 T*("  0T].5%))0E543U)3($)%($Q)04),12!&
M3U( 04Y9($1)4D5#5"P 24Y$25)%0U0L($E.0TE$14Y404PL(%-014-)04PL
M#0H ("!%6$5-4$Q!4EDL($]2($-/3E-%455%3E1)04P 1$%-04=%4R H24Y#
M3%5$24Y'+"!"550 3D]4($Q)34E4140 5$\L#0H ("!04D]#55)%345.5"!/
M1B!354)35$E4551%($=/3T13($]2(%-%4E9)0T53.R!,3U-3($]&(%5312P 
M1$%402P 3U(-"B  (%!23T9)5%,[($]2($)54TE.15-3($E.5$524E505$E/
M3BD 2$]7159%4B!#0553140 04Y$($].($%.62!42$5/4ED 3T8-"B  ($Q)
M04))3$E462P 5TA%5$A%4B!)3B!#3TY44D%#5"P 4U1224-4($Q)04))3$E4
M62P 3U( 5$]25" H24Y#3%5$24Y'#0H ("!.14=,24=%3D-%($]2($]42$52
M5TE312D 05))4TE.1R!)3B!!3ED 5T%9($]55"!/1B!42$4 55-%($]&(%1(
M25,-"B  (%-/1E1705)%+"!%5D5.($E&($%$5DE3140 3T8 5$A%(%!/4U-)
M0DE,2519($]&(%-50T  1$%-04=%+ T*#0H ("!4:&4 ;W)I9VEN86P 8V]D
M92!I;F-L=61E9"!T:&4 9F]L;&]W:6YG(&YO=&EC93H-"B  #0H ("  ($%N
M>2!F965D8F%C:R!I<R!V97)Y('=E;&-O;64N#0H ("  (&AT=' Z+R]W=W<N
M;6%T:"YK96EO+F%C+FIP+VUA='5M;W1O+V5M="YH=&UL#0H ("  (&5M86EL
M.B!M871U;6]T;T!M871H+FME:6\N86,N:G -"B  #0H ("!0;&5A<V4 0T,Z
M(&5D=V%R9'-A8T!I965E+F]R9R!O;B!A;&P 8V]R<F5S<&]N9&5N8V4-"BHO
M#0H-"FUO9'5L92!-97)S96YN951W:7-T97([#0II;7!O<G0 <W1R96%M.PT*
M#0HO*B!097)I;V0 <&%R86UE=&5R<R J+R  #0IC;VYS="!I;G0 3B ](#8R
M-#L-"F-O;G-T(&EN="!-(#T ,SDW.PT*8V]N<W0 =6EN="!-051225A?02 ]
M(#!X.3DP.&(P9&953#L (" O*B!C;VYS=&%N="!V96-T;W( 82 J+PT*8V]N
M<W0 =6EN="!534%32R ](#!X.# P,# P,#!53#L +RH ;6]S="!S:6=N:69I
M8V%N="!W+7( 8FET<R J+PT*8V]N<W0 =6EN="!,34%32R ](#!X-V9F9F9F
M9F953#L +RH ;&5A<W0 <VEG;FEF:6-A;G0 <B!B:71S("HO#0IU:6YT($U)
M6$))5%,H=6EN="!U+"!U:6YT('8I('L <F5T=7)N("AU("8 54U!4TLI('P 
M*'8 )B!,34%32RD[('T-"G5I;G0 5%=)4U0H=6EN="!U+'5I;G0 =BD >R!R
M971U<FX *$U)6$))5%,H=2QV*2 ^/B Q*2!>("AV)C$ /R!-051225A?02 Z
M(# I.R!]#0H-"G-T871I8R!U:6YT('-T871E6TY=.R O*B!T:&4 87)R87D 
M9F]R('1H92!S=&%T92!V96-T;W( ("HO#0IS=&%T:6, :6YT(&QE9G0 /2 Q
M.PT*<W1A=&EC(&EN="!I;FET9B ](# [#0IS=&%T:6, =6EN=" J;F5X=#L-
M" T*+RH :6YI=&EA;&EZ97, <W1A=&5;3ET =VET:"!A('-E960 *B\-"G9O
M:60 :6YI=%]G96YR86YD*'5I;G0 <RD-"GL-"B  ("!S=&%T95LP73T <R F
M(#!X9F9F9F9F9F953#L-"B  ("!F;W( *&EN="!J/3$[(&H\3CL :BLK*2![
M#0H ("  ("  ('-T871E6VI=(#T *#$X,3(T,S,R-3-53" J("AS=&%T95MJ
M+3%=(%X *'-T871E6VHM,5T /CX ,S I*2 K(&HI.R -"B  ("  ("  +RH 
M4V5E($MN=71H(%1!3T-0(%9O;#(N(#-R9"!%9"X 4"XQ,#8 9F]R(&UU;'1I
M<&QI97(N("HO#0H ("  ("  ("\J($EN('1H92!P<F5V:6]U<R!V97)S:6]N
M<RP 35-"<R!O9B!T:&4 <V5E9"!A9F9E8W0 (" J+PT*("  ("  (" O*B!O
M;FQY($U30G, ;V8 =&AE(&%R<F%Y('-T871E6UTN("  ("  ("  ("  ("  
M("  ("  ("  *B\-"B  ("  ("  +RH ,C P,B\P,2\P.2!M;V1I9FEE9"!B
M>2!-86MO=&\ 36%T<W5M;W1O("  ("  ("  ("  ("HO#0H ("  ("  ('-T
M871E6VI=("8](#!X9F9F9F9F9F953#L ("\J(&9O<B ^,S( 8FET(&UA8VAI
M;F5S("HO#0H ("  ?0T*("  (&QE9G0 /2 Q.R!I;FET9B ](#$[#0I]#0H-
M"B\J(&EN:71I86QI>F4 8GD 86X 87)R87D =VET:"!A<G)A>2UL96YG=&  
M*B\-"B\J(&EN:71?:V5Y(&ES('1H92!A<G)A>2!F;W( :6YI=&EA;&EZ:6YG
M(&ME>7, *B\-"B\J(&ME>5]L96YG=&  :7, :71S(&QE;F=T:" J+PT*+R]U
M:6YT(&EN:71?:V5Y6UT[#0HO+W5I;G0 :V5Y7VQE;F=T:#L-"G9O:60 :6YI
M=%]B>5]A<G)A>2AU:6YT(&EN:71?:V5Y6UTL('5I;G0 :V5Y7VQE;F=T:"D-
M"GL-"B  ("!I;G0 :2P :BP :SL-"B  ("!I;FET7V=E;G)A;F0H,3DV-3 R
M,3A53"D[#0H ("  :3TQ.R!J/3 [#0H ("  :R ]("A./FME>5]L96YG=&  
M/R!.(#H :V5Y7VQE;F=T:"D[#0H ("  9F]R(" [(&L[(&LM+2D >PT*("  
M("  ("!S=&%T95MI72 ]("AS=&%T95MI72!>(" H<W1A=&5;:2TQ72!>("AS
M=&%T95MI+3%=(#X^(#,P*2D *B Q-C8T-3(U54PI*0T*("  ("  ("  ("L 
M:6YI=%]K97E;:ET *R!J.R O*B!N;VX ;&EN96%R("HO#0H ("  ("  ('-T
M871E6VE=("8](#!X9F9F9F9F9F953#L +RH 9F]R(%=/4D1325I%(#X ,S( 
M;6%C:&EN97, *B\-"B  ("  ("  :2LK.R!J*RL[#0H ("  ("  (&EF("AI
M/CU.*2![('-T871E6S!=(#T <W1A=&5;3BTQ73L :3TQ.R!]#0H ("  ("  
M(&EF("AJ/CUK97E?;&5N9W1H*2!J/3 [#0H ("  ?0T*("  (&9O<B H:SU.
M+3$[(&L[(&LM+2D >PT*("  ("  ("!S=&%T95MI72 ]("AS=&%T95MI72!>
M(" H<W1A=&5;:2TQ72!>("AS=&%T95MI+3%=(#X^(#,P*2D *B Q-38V,# S
M.30Q54PI*0T*("  ("  ("  ("T :3L +RH ;F]N(&QI;F5A<B J+PT*("  
M("  ("!S=&%T95MI72 F/2 P>&9F9F9F9F9F54P[("\J(&9O<B!73U)$4TE:
M12 ^(#,R(&UA8VAI;F5S("HO#0H ("  ("  (&DK*SL-"B  ("  ("  :68 
M*&D^/4XI('L <W1A=&5;,%T /2!S=&%T95M.+3%=.R!I/3$[('T-"B  ("!]
M#0H-"B  ("!S=&%T95LP72 ](#!X.# P,# P,#!53#L +RH 35-"(&ES(#$[
M(&%S<W5R:6YG(&YO;BUZ97)O(&EN:71I86P 87)R87D *B\ #0H ("  ;&5F
M=" ](#$[(&EN:71F(#T ,3L-"GT-" T*<W1A=&EC('9O:60 ;F5X=%]S=&%T
M92 I#0I[#0H ("  =6EN=" J<#US=&%T93L-" T*("  ("\J(&EF(&EN:71?
M9V5N<F%N9" I(&AA<R!N;W0 8F5E;B!C86QL960L("HO#0H ("  +RH 82!D
M969A=6QT(&EN:71I86P <V5E9"!I<R!U<V5D("  ("  ("  *B\-"B  ("!I
M9B H:6YI=&8]/3 I(&EN:71?9V5N<F%N9" U-# Y54PI.PT*#0H ("  ;&5F
M=" ]($X[#0H ("  ;F5X=" ]('-T871E.PT*("  ( T*("  (&9O<B H:6YT
M(&H]3BU-*S$[("TM:CL <"LK*2 -"B  ("  ("  *G  /2!P6TU=(%X 5%=)
M4U0H<%LP72P <%LQ72D[#0H-"B  ("!F;W( *&EN="!J/4T[("TM:CL <"LK
M*2 -"B  ("  ("  *G  /2!P6TTM3ET 7B!45TE35"AP6S!=+"!P6S%=*3L-
M" T*("  ("IP(#T <%M-+4Y=(%X 5%=)4U0H<%LP72P <W1A=&5;,%TI.PT*
M?0T*#0HO*B!G96YE<F%T97, 82!R86YD;VT ;G5M8F5R(&]N(%LP+#!X9F9F
M9F9F9F9=+6EN=&5R=F%L("HO#0IU:6YT(&=E;G)A;F1?:6YT,S(H*0T*>PT*
M("  ('5I;G0 >3L-" T*("  (&EF(" M+6QE9G0 /3T ,"D ;F5X=%]S=&%T
M92 I.PT*("  ('D /2 J;F5X="LK.PT*#0H ("  +RH 5&5M<&5R:6YG("HO
M#0H ("  >2!>/2 H>2 ^/B Q,2D[#0H ("  >2!>/2 H>2 \/" W*2 F(#!X
M.60R8S4V.#!53#L-"B  ("!Y(%X]("AY(#P\(#$U*2 F(#!X969C-C P,#!5
M3#L-"B  ("!Y(%X]("AY(#X^(#$X*3L-" T*("  (')E='5R;B!Y.PT*?0T*
M#0HO*B!G96YE<F%T97, 82!R86YD;VT ;G5M8F5R(&]N(%LP+#!X-V9F9F9F
M9F9=+6EN=&5R=F%L("HO#0IL;VYG(&=E;G)A;F1?:6YT,S$H*0T*>PT*("  
M('5I;G0 >3L-" T*("  (&EF(" M+6QE9G0 /3T ,"D ;F5X=%]S=&%T92 I
M.PT*("  ('D /2 J;F5X="LK.PT*#0H ("  +RH 5&5M<&5R:6YG("HO#0H 
M("  >2!>/2 H>2 ^/B Q,2D[#0H ("  >2!>/2 H>2 \/" W*2 F(#!X.60R
M8S4V.#!53#L-"B  ("!Y(%X]("AY(#P\(#$U*2 F(#!X969C-C P,#!53#L-
M"B  ("!Y(%X]("AY(#X^(#$X*3L-" T*("  (')E='5R;B H;&]N9RDH>3X^
M,2D[#0I]#0H-"B\J(&=E;F5R871E<R!A(')A;F1O;2!N=6UB97( ;VX 6S L
M,5TM<F5A;"UI;G1E<G9A;" J+PT*9&]U8FQE(&=E;G)A;F1?<F5A;#$H*0T*
M>PT*("  ('5I;G0 >3L-" T*("  (&EF(" M+6QE9G0 /3T ,"D ;F5X=%]S
M=&%T92 I.PT*("  ('D /2 J;F5X="LK.PT*#0H ("  +RH 5&5M<&5R:6YG
M("HO#0H ("  >2!>/2 H>2 ^/B Q,2D[#0H ("  >2!>/2 H>2 \/" W*2 F
M(#!X.60R8S4V.#!53#L-"B  ("!Y(%X]("AY(#P\(#$U*2 F(#!X969C-C P
M,#!53#L-"B  ("!Y(%X]("AY(#X^(#$X*3L-" T*("  (')E='5R;B H9&]U
M8FQE*7D *B H,2XP+S0R.30Y-C<R.34N,"D[( T*("  ("\J(&1I=FED960 
M8GD ,EXS,BTQ("HO( T*?0T*#0HO*B!G96YE<F%T97, 82!R86YD;VT ;G5M
M8F5R(&]N(%LP+#$I+7)E86PM:6YT97)V86P *B\-"F1O=6)L92!G96YR86YD
M7W)E86PR*"D-"GL-"B  ("!U:6YT('D[#0H-"B  ("!I9B H+2UL969T(#T]
M(# I(&YE>'1?<W1A=&4H*3L-"B  ("!Y(#T *FYE>'0K*SL-" T*("  ("\J
M(%1E;7!E<FEN9R J+PT*("  ('D 7CT *'D /CX ,3$I.PT*("  ('D 7CT 
M*'D /#P -RD )B P>#ED,F,U-C P54P[#0H ("  >2!>/2 H>2 \/" Q-2D 
M)B P>&5F8S8P,# P54P[#0H ("  >2!>/2 H>2 ^/B Q."D[#0H-"B  ("!R
M971U<FX *&1O=6)L92EY("H *#$N,"\T,CDT.38W,CDV+C I.R -"B  (" O
M*B!D:79I9&5D(&)Y(#)>,S( *B\-"GT-" T*+RH 9V5N97)A=&5S(&$ <F%N
M9&]M(&YU;6)E<B!O;B H,"PQ*2UR96%L+6EN=&5R=F%L("HO#0ID;W5B;&4 
M9V5N<F%N9%]R96%L,R I#0I[#0H ("  =6EN="!Y.PT*#0H ("  :68 *"TM
M;&5F=" ]/2 P*2!N97AT7W-T871E*"D[#0H ("  >2 ]("IN97AT*RL[#0H-
M"B  (" O*B!496UP97)I;F< *B\-"B  ("!Y(%X]("AY(#X^(#$Q*3L-"B  
M("!Y(%X]("AY(#P\(#<I("8 ,' Y9#)C-38X,%5,.PT*("  ('D 7CT *'D 
M/#P ,34I("8 ,'AE9F,V,# P,%5,.PT*("  ('D 7CT *'D /CX ,3 I.PT*
M#0H ("  <F5T=7)N(" H9&]U8FQE*7D *R P+C4I("H *#$N,"\T,CDT.38W
M,CDV+C I.R -"B  (" O*B!D:79I9&5D(&)Y(#)>,S( *B\-"GT-" T*+RH 
M9V5N97)A=&5S(&$ <F%N9&]M(&YU;6)E<B!O;B!;,"PQ*2!W:71H(#4S+6)I
M="!R97-O;'5T:6]N*B\-"F1O=6)L92!G96YR86YD7W)E<S4S*"D #0I[( T*
M("  ('5I;G0 83UG96YR86YD7VEN=#,R*"D^/C4L(&(]9V5N<F%N9%]I;G0S
M,B I/CXV.R -"B  ("!R971U<FXH82HV-S$P.# V-"XP*V(I*B Q+C O.3 P
M-S$Y.3(U-#<T,#DY,BXP*3L #0I]( T*+RH 5&AE<V4 <F5A;"!V97)S:6]N
M<R!A<F4 9'5E('1O($ES86MU(%=A9&$L(#(P,#(O,#$O,#D 861D960 *B\-
M" T*:6YT(&UA:6XH*0T*>PT*("  ('-T871I8R!U:6YT(&EN:71;-%T]6S!X
M,3(S+" P>#(S-"P ,' S-#4L(#!X-#4V73L-"B  ("!U:6YT(&QE;F=T:#TT
M.PT*("  (&EN:71?8GE?87)R87DH:6YI="P ;&5N9W1H*3L-"B  (" O*B!4
M:&ES(&ES(&%N(&5X86UP;&4 ;V8 :6YI=&EA;&EZ:6YG(&)Y(&%N(&%R<F%Y
M+B  ("  (" J+PT*("  ("\J(%EO=2!M87D =7-E(&EN:71?9V5N<F%N9"AS
M965D*2!W:71H(&%N>2 S,F)I="!I;G1E9V5R("HO#0H ("  +RH 87, 82!S
M965D(&9O<B!A('-I;7!L97( :6YI=&EA;&EZ871I;VX ("  ("  ("  ("  
M("  *B\-"B  ("!P<FEN=&8H(C$P,#  ;W5T<'5T<R!O9B!G96YR86YD7VEN
M=#,R*"E<;B(I.PT*("  (&9O<B H:6YT(&D],#L :3PQ,# P.R!I*RLI('L-
M"B  ("  ('!R:6YT9B B)3$P;'4 (BP 9V5N<F%N9%]I;G0S,B I*3L-"B  
M("  (&EF("AI)34]/30I('!R:6YT9B B7&XB*3L-"B  ("!]#0H ("  <')I
M;G1F*")<;C$P,#  ;W5T<'5T<R!O9B!G96YR86YD7W)E86PR*"E<;B(I.PT*
M("  (&9O<B H:6YT(&D],#L :3PQ,# P.R!I*RLI('L-"B  ("  ('!R:6YT
M9B B)3$P+CAF("(L(&=E;G)A;F1?<F5A;#(H*2D[#0H ("  ("!I9B H:24U
M/3TT*2!P<FEN=&8H(EQN(BD[#0H ("  ?0T*#0H ("  <F5T=7)N(# [#0I]
M#0H-"B\O($-H86YG92!L;V<Z#0HO+PT*+R\ =C N,2 M($9I<G-T(')E;&5A
M<V4 ;VX ,S  4V5P=&5M8F5R(#(P,#,-"B\O("  ("  +2!4<F%N<VQA=&5D
,(&9R;VT 0R!T;R!$
`
end
Sep 30 2003
next sibling parent Olaf Rogalsky <olaf.rogalsky theorie1.physik.uni-erlangen.de> writes:
Andrew Edwards wrote:
 I've successfully compiled the Mersenne Twister RNG in D.  In it's current
 state, it is simply a C program modified to compile in D. I would like to
 make it a true "D" program and would appreciate some suggestions on how to
 improve upon it! 
Congratulations, MT is my favorite RNG: Both, fast and without known deficiencies.
 As pointed out by the original authors
 (http://www.math.keio.ac.jp/matumoto/emt.html), MT is "NOT SECURE for
 CRYPTOGRAPHY", I would like to remedy this situation 
Well, I wish you good luck, but this is not an easy task. Good security mainly stems from two aspects of the RNG: 1) Randomness. Software RNG's aren't random at all, once the seed is known, the sequence is completely predictable. Therefore, the RNG's in cryptographic software is continuously seeded with truly random data from some source of entropy. This truly random data usually is drawn from monitored system events, like the time interval between two successive key strokes or the time interval between the arrival of two network packets. Of course these data events are highly correlated and therefore not suitable for cryptography. The subject of the RNG then is to mix and mangle the correlated data to a new sequence of data, which is not obviously correlated. 2) Invertability. Consider the (mathematical) function f, which maps the seed data to the random numbers. For simplicity lets assume, that f is bijective, such that there exists a inverse function g: g(f(x))=f(g(x))=x. If it is feasible to compute the inverse function g, then an attacker could compute the seed data from the output of the RNG. But since the seed data is highly correlated, he can predict with good probability the seed data for the next random number. But if he knows the seed, he easily can compute the next random number by applying the function f to the new seed. You therefore must prove (if you do so, you probably will be awarded the Fields Medal) or at least make plausible to the experts, that it is unfeasible to compute the inverse function g.
 and eventually provide
 an OO version of the RNG.
Why the hack an OO version??? What's the benefit of it? Just provide a simple API for the production of random numbers, drawn from some random distribution, most importantly: Uniformly distributed integers in some range. Uniformly distributed floats/doubles in some range. Binomial distributed integers. Poissonian distributed floats/doubles. Gaussian distributed floats/doubles. I hope, I haven't been too discouraging, cheers Olaf -- +----------------------------------------------------------------------+ I Dr. Olaf Rogalsky Institut f. Theo. Physik I I I Tel.: 09131 8528440 Univ. Erlangen-Nuernberg I I Fax.: 09131 8528444 Staudtstrasse 7 B3 I I rogalsky theorie1.physik.uni-erlangen.de D-91058 Erlangen I +----------------------------------------------------------------------+
Sep 30 2003
prev sibling parent Helmut Leitner <leitner hls.via.at> writes:
Andrew Edwards wrote:
 
 Gentlemen, (Are there any ladies here?)
 
 I've successfully compiled the Mersenne Twister RNG in D.  In it's current
 state, it is simply a C program modified to compile in D. I would like to
 make it a true "D" program and would appreciate some suggestions on how to
 improve upon it! As pointed out by the original authors
 (http://www.math.keio.ac.jp/matumoto/emt.html), MT is "NOT SECURE for
 CRYPTOGRAPHY", I would like to remedy this situation and eventually provide
 an OO version of the RNG.
 
 All guidance and suggestions will be greatly appreciated.
 Code is attached.
Sometime ago I started a experimental Venus library as a testbed for future Modules to Phobos / standard library. As part of it I reworked the existing Phobos random generator to separate the generator part from special functions like producing numbers for an integer or fp range or for Gauss distributions. The generators are also pluggable via an interface. Your work would fit nicely in. The MT could be a third generator, the 53-bit-part a nice addition to the "outer layer" of the system usable with any other generator too. Take a look at my code at: <http://www.prowiki.org/wiki4d/wiki.cgi?VenusLibrary> - interfaces.d - random1.d - random2.d If you can live with the "Donation to Digital Mars" statement, you can do the integration yourself or leave the task to me. I suppose it will make its way (not necessarily in this exact form for library standards are not yet discussed) to a future standard library sooner or later. If have have any additional random number expert knowledge it would be nice to integrate it into the environment. Anyway, thank you for your work! -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Sep 30 2003