├── README.md ├── aes256cbc ├── README.md ├── aes256cbc.go ├── aes256cbc_test.go └── examples_test.go ├── dh64 ├── README.md ├── c │ ├── dh64.c │ ├── dh64.h │ └── dh64_test.c ├── csharp │ ├── dh64.cs │ └── dh64_test.cs └── go │ ├── dh64.go │ └── dh64_test.go ├── mt19937 ├── README.md ├── c │ ├── mt19937-64.c │ ├── mt19937-64.h │ ├── mt19937-64.out.txt │ └── mt19937-64test.c ├── csharp │ ├── mt19937.cs │ └── mt19937_test.cs └── go │ ├── COPYING │ ├── README.rst │ ├── doc.go │ ├── example.go │ ├── mt19937.go │ └── mt19937_test.go └── rc4 ├── README.md ├── csharp ├── rc4.cs └── rc4_echo_client.cs └── go ├── rc4_echo_client.go └── rc4_echo_server.go /README.md: -------------------------------------------------------------------------------- 1 | 一些涉及到加密和安全的代码。 -------------------------------------------------------------------------------- /aes256cbc/README.md: -------------------------------------------------------------------------------- 1 | # This package fork from github.com/luzifer/go-openssl 2 | 3 | `go-openssl` is a small library wrapping the `crypto/aes` functions in a way the output is compatible to OpenSSL / CryptoJS. For all encryption / decryption processes AES256 is used so this library will not be able to decrypt messages generated with other than `openssl aes-256-cbc`. If you're using CryptoJS to process the data you also need to use AES256 on that side. 4 | 5 | ## Installation 6 | 7 | ``` 8 | git clone https://github.com/funny/crypto 9 | ``` 10 | 11 | ## Usage example 12 | 13 | The usage is quite simple as you don't need any special knowledge about OpenSSL and/or AES256: 14 | 15 | ### Encrypt 16 | 17 | ```go 18 | import ( 19 | "fmt" 20 | "github.com/funny/crypto/aes256cbc" 21 | ) 22 | 23 | func main() { 24 | plaintext := "Hello World!" 25 | passphrase := "z4yH36a6zerhfE5427ZV" 26 | 27 | enc, err := aes256cbc.EncryptString(passphrase, plaintext) 28 | if err != nil { 29 | fmt.Printf("An error occurred: %s\n", err) 30 | } 31 | 32 | fmt.Printf("Encrypted text: %s\n", string(enc)) 33 | } 34 | ``` 35 | 36 | ### Decrypt 37 | 38 | ```go 39 | import ( 40 | "fmt" 41 | "github.com/funny/crypto/aes256cbc" 42 | ) 43 | 44 | func main() { 45 | opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU=" 46 | passphrase := "z4yH36a6zerhfE5427ZV" 47 | 48 | dec, err := aes256cbc.DecryptString(passphrase, opensslEncrypted) 49 | if err != nil { 50 | fmt.Printf("An error occurred: %s\n", err) 51 | } 52 | 53 | fmt.Printf("Decrypted text: %s\n", string(dec)) 54 | } 55 | ``` 56 | 57 | ## Testing 58 | 59 | To execute the tests for this library you need to be on a system having `/bin/bash` and `openssl` available as the compatibility of the output is tested directly against the `openssl` binary. The library itself should be usable on all operating systems supported by Go and `crypto/aes`. 60 | -------------------------------------------------------------------------------- /aes256cbc/aes256cbc.go: -------------------------------------------------------------------------------- 1 | // Package aes256cbc is a helper to generate OpenSSL compatible encryption 2 | // with autmatic IV derivation and storage. As long as the key is known all 3 | // data can also get decrypted using OpenSSL CLI. 4 | // Code from http://dequeue.blogspot.de/2014/11/decrypting-something-encrypted-with.html 5 | package aes256cbc 6 | 7 | import ( 8 | "bytes" 9 | "crypto/aes" 10 | "crypto/cipher" 11 | "crypto/md5" 12 | "crypto/rand" 13 | "encoding/base64" 14 | "fmt" 15 | "io" 16 | ) 17 | 18 | // OpenSSL salt is always this string + 8 bytes of actual salt 19 | var openSSLSaltHeader = []byte("Salted__") 20 | 21 | type openSSLCreds [48]byte 22 | 23 | // openSSLEvpBytesToKey follows the OpenSSL (undocumented?) convention for extracting the key and IV from passphrase. 24 | // It uses the EVP_BytesToKey() method which is basically: 25 | // D_i = HASH^count(D_(i-1) || password || salt) where || denotes concatentaion, until there are sufficient bytes available 26 | // 48 bytes since we're expecting to handle AES-256, 32bytes for a key and 16bytes for the IV 27 | func (c *openSSLCreds) Extract(password, salt []byte) (key, iv []byte) { 28 | m := c[:] 29 | buf := make([]byte, 0, 16+len(password)+len(salt)) 30 | var prevSum [16]byte 31 | for i := 0; i < 3; i++ { 32 | n := 0 33 | if i > 0 { 34 | n = 16 35 | } 36 | buf = buf[:n+len(password)+len(salt)] 37 | copy(buf, prevSum[:]) 38 | copy(buf[n:], password) 39 | copy(buf[n+len(password):], salt) 40 | prevSum = md5.Sum(buf) 41 | copy(m[i*16:], prevSum[:]) 42 | } 43 | return c[:32], c[32:] 44 | } 45 | 46 | // DecryptString decrypts a base64 encoded string that was encrypted using OpenSSL and AES-256-CBC. 47 | func DecryptString(passphrase, encryptedBase64String string) (string, error) { 48 | text, err := DecryptBase64([]byte(passphrase), []byte(encryptedBase64String)) 49 | return string(text), err 50 | } 51 | 52 | // DecryptBase64 decrypts a base64 encoded []byte that was encrypted using OpenSSL and AES-256-CBC. 53 | func DecryptBase64(passphrase, encryptedBase64 []byte) ([]byte, error) { 54 | encrypted := make([]byte, base64.StdEncoding.DecodedLen(len(encryptedBase64))) 55 | n, err := base64.StdEncoding.Decode(encrypted, encryptedBase64) 56 | if err != nil { 57 | return nil, err 58 | } 59 | return Decrypt(passphrase, encrypted[:n]) 60 | } 61 | 62 | // Decrypt decrypts a []byte that was encrypted using OpenSSL and AES-256-CBC. 63 | func Decrypt(passphrase, encrypted []byte) ([]byte, error) { 64 | if len(encrypted) < aes.BlockSize { 65 | return nil, fmt.Errorf("Cipher data length less than aes block size") 66 | } 67 | saltHeader := encrypted[:aes.BlockSize] 68 | if !bytes.Equal(saltHeader[:8], openSSLSaltHeader) { 69 | return nil, fmt.Errorf("Does not appear to have been encrypted with OpenSSL, salt header missing.") 70 | } 71 | var creds openSSLCreds 72 | key, iv := creds.Extract(passphrase, saltHeader[8:]) 73 | 74 | if len(encrypted) == 0 || len(encrypted)%aes.BlockSize != 0 { 75 | return nil, fmt.Errorf("bad blocksize(%v), aes.BlockSize = %v\n", len(encrypted), aes.BlockSize) 76 | } 77 | c, err := aes.NewCipher(key) 78 | if err != nil { 79 | return nil, err 80 | } 81 | cbc := cipher.NewCBCDecrypter(c, iv) 82 | cbc.CryptBlocks(encrypted[aes.BlockSize:], encrypted[aes.BlockSize:]) 83 | return pkcs7Unpad(encrypted[aes.BlockSize:]) 84 | } 85 | 86 | // EncryptString encrypts a string in a manner compatible to OpenSSL encryption 87 | // functions using AES-256-CBC as encryption algorithm and encode to base64 format. 88 | func EncryptString(passphrase, plaintextString string) (string, error) { 89 | encryptedBase64, err := EncryptBase64([]byte(passphrase), []byte(plaintextString)) 90 | return string(encryptedBase64), err 91 | } 92 | 93 | // EncryptBase64 encrypts a []byte in a manner compatible to OpenSSL encryption 94 | // functions using AES-256-CBC as encryption algorithm and encode to base64 format. 95 | func EncryptBase64(passphrase, plaintext []byte) ([]byte, error) { 96 | encrypted, err := Encrypt(passphrase, plaintext) 97 | encryptedBase64 := make([]byte, base64.StdEncoding.EncodedLen(len(encrypted))) 98 | base64.StdEncoding.Encode(encryptedBase64, encrypted) 99 | return encryptedBase64, err 100 | } 101 | 102 | // Encrypt encrypts a []byte in a manner compatible to OpenSSL encryption 103 | // functions using AES-256-CBC as encryption algorithm 104 | func Encrypt(passphrase, plaintext []byte) ([]byte, error) { 105 | var salt [8]byte // Generate an 8 byte salt 106 | _, err := io.ReadFull(rand.Reader, salt[:]) 107 | if err != nil { 108 | return nil, err 109 | } 110 | 111 | data := make([]byte, len(plaintext)+aes.BlockSize, len(plaintext)+aes.BlockSize+1 /* for append '\n' */) 112 | copy(data[0:], openSSLSaltHeader) 113 | copy(data[8:], salt[:]) 114 | copy(data[aes.BlockSize:], plaintext) 115 | 116 | var creds openSSLCreds 117 | key, iv := creds.Extract(passphrase, salt[:]) 118 | encrypted, err := encrypt(key, iv, data) 119 | if err != nil { 120 | return nil, err 121 | } 122 | return encrypted, nil 123 | } 124 | 125 | func encrypt(key, iv, data []byte) ([]byte, error) { 126 | padded, err := pkcs7Pad(data) 127 | if err != nil { 128 | return nil, err 129 | } 130 | c, err := aes.NewCipher(key) 131 | if err != nil { 132 | return nil, err 133 | } 134 | cbc := cipher.NewCBCEncrypter(c, iv) 135 | cbc.CryptBlocks(padded[aes.BlockSize:], padded[aes.BlockSize:]) 136 | return padded, nil 137 | } 138 | 139 | var padPatterns [aes.BlockSize+1][]byte 140 | 141 | func init() { 142 | for i := 0; i < len(padPatterns); i++ { 143 | padPatterns[i] = bytes.Repeat([]byte{byte(i)}, i) 144 | } 145 | } 146 | 147 | // pkcs7Pad appends padding. 148 | func pkcs7Pad(data []byte) ([]byte, error) { 149 | if len(data)%aes.BlockSize == 0 { 150 | return data, nil 151 | } 152 | padlen := 1 153 | for ((len(data) + padlen) % aes.BlockSize) != 0 { 154 | padlen = padlen + 1 155 | } 156 | return append(data, padPatterns[padlen]...), nil 157 | } 158 | 159 | // pkcs7Unpad returns slice of the original data without padding. 160 | func pkcs7Unpad(data []byte) ([]byte, error) { 161 | if len(data)%aes.BlockSize != 0 || len(data) == 0 { 162 | return nil, fmt.Errorf("invalid data len %d", len(data)) 163 | } 164 | padlen := int(data[len(data)-1]) 165 | if padlen > aes.BlockSize || padlen == 0 { 166 | return nil, fmt.Errorf("invalid padding") 167 | } 168 | if !bytes.Equal(padPatterns[padlen], data[len(data)-padlen:]) { 169 | return nil, fmt.Errorf("invalid padding") 170 | } 171 | return data[:len(data)-padlen], nil 172 | } 173 | -------------------------------------------------------------------------------- /aes256cbc/aes256cbc_test.go: -------------------------------------------------------------------------------- 1 | package aes256cbc 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os/exec" 7 | "testing" 8 | ) 9 | 10 | func Benchmark_Decrypt(b *testing.B) { 11 | opensslEncrypted := []byte("U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU=") 12 | passphrase := []byte("z4yH36a6zerhfE5427ZV") 13 | for i := 0; i < b.N; i++ { 14 | DecryptBase64(passphrase, opensslEncrypted) 15 | } 16 | } 17 | 18 | func TestDecryptFromString(t *testing.T) { 19 | // > echo -n "hallowelt" | openssl aes-256-cbc -pass pass:z4yH36a6zerhfE5427ZV -a -salt 20 | // U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU= 21 | 22 | opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU=" 23 | passphrase := "z4yH36a6zerhfE5427ZV" 24 | 25 | data, err := DecryptString(passphrase, opensslEncrypted) 26 | 27 | if err != nil { 28 | t.Fatalf("Test errored: %s", err) 29 | } 30 | 31 | if string(data) != "hallowelt" { 32 | t.Errorf("Decryption output did not equal expected output.") 33 | } 34 | } 35 | 36 | func TestEncryptToDecrypt(t *testing.T) { 37 | plaintext := "hallowelt" 38 | passphrase := "z4yH36a6zerhfE5427ZV" 39 | 40 | enc, err := EncryptString(passphrase, plaintext) 41 | if err != nil { 42 | t.Fatalf("Test errored at encrypt: %s", err) 43 | } 44 | 45 | dec, err := DecryptString(passphrase, string(enc)) 46 | if err != nil { 47 | t.Fatalf("Test errored at decrypt: %s", err) 48 | } 49 | 50 | if string(dec) != plaintext { 51 | t.Errorf("Decrypted text did not match input.") 52 | } 53 | } 54 | 55 | func TestEncryptToOpenSSL(t *testing.T) { 56 | plaintext := "hallowelt" 57 | passphrase := "z4yH36a6zerhfE5427ZV" 58 | 59 | enc, err := EncryptString(passphrase, plaintext) 60 | if err != nil { 61 | t.Fatalf("Test errored at encrypt: %s", err) 62 | } 63 | 64 | // WTF? Without "echo" openssl tells us "error reading input file" 65 | cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("echo \"%s\" | openssl aes-256-cbc -k %s -d -a", string(enc), passphrase)) 66 | 67 | var out bytes.Buffer 68 | cmd.Stdout = &out 69 | cmd.Stderr = &out 70 | 71 | err = cmd.Run() 72 | if err != nil { 73 | t.Errorf("OpenSSL errored: %s", err) 74 | } 75 | 76 | if out.String() != plaintext { 77 | t.Errorf("OpenSSL output did not match input.\nOutput was: %s", out.String()) 78 | } 79 | } 80 | 81 | func TestDecryptFromOpenSSL(t *testing.T) { 82 | plaintext := "192.168.2.2:8080" 83 | passphrase := "sofunny" 84 | 85 | // WTF? Without "echo" openssl tells us "error reading input file" 86 | cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("echo -n \"%s\" | openssl enc -e -aes-256-cbc -a -salt -k %s", plaintext, passphrase)) 87 | 88 | var out bytes.Buffer 89 | cmd.Stdout = &out 90 | cmd.Stderr = &out 91 | 92 | err := cmd.Run() 93 | if err != nil { 94 | t.Errorf("OpenSSL errored: %s", err) 95 | } 96 | 97 | dec, err := DecryptString(passphrase, out.String()) 98 | if err != nil { 99 | t.Fatalf("Test errored at decrypt: %s\n.Output was: %s", err, out.String()) 100 | } 101 | 102 | if string(dec) != plaintext { 103 | t.Errorf("Decrypted text did not match input.") 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /aes256cbc/examples_test.go: -------------------------------------------------------------------------------- 1 | package aes256cbc 2 | 3 | import "fmt" 4 | 5 | func ExampleEncryptString() { 6 | plaintext := "Hello World!" 7 | passphrase := "z4yH36a6zerhfE5427ZV" 8 | 9 | enc, err := EncryptString(passphrase, plaintext) 10 | if err != nil { 11 | fmt.Printf("An error occurred: %s\n", err) 12 | } 13 | 14 | fmt.Printf("Encrypted text: %s\n", string(enc)) 15 | } 16 | 17 | func ExampleDecryptString() { 18 | opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU=" 19 | passphrase := "z4yH36a6zerhfE5427ZV" 20 | 21 | dec, err := DecryptString(passphrase, opensslEncrypted) 22 | if err != nil { 23 | fmt.Printf("An error occurred: %s\n", err) 24 | } 25 | 26 | fmt.Printf("Decrypted text: %s\n", string(dec)) 27 | 28 | // Output: 29 | // Decrypted text: hallowelt 30 | } 31 | -------------------------------------------------------------------------------- /dh64/README.md: -------------------------------------------------------------------------------- 1 | 64位的迪菲-赫尔曼密钥交换算法代码集 2 | =============================== 3 | 4 | 迪菲-赫尔曼密钥交换(英语:Diffie–Hellman key exchange,简称“D-H”) 是一种安全协议。 5 | 6 | 它可以让双方在完全没有对方任何预先信息的条件下通过不安全信道创建起一个密钥。这个密钥可以在后续的通讯中作为对称密钥来加密通讯内容。 7 | 8 | 迪菲-赫尔曼密钥交换的同义词包括: 9 | 10 | * 迪菲-赫尔曼密钥协商 11 | * 迪菲-赫尔曼密钥创建 12 | * 迪菲-赫尔曼协议 13 | * 指数密钥交换 14 | 15 | 虽然迪菲-赫尔曼密钥交换本身是一个匿名(无认证)的 密钥交换协议,它却是很多认证协议的基础,并且被用来提供传输层安全协议的短暂模式中的完备的前向安全性。 16 | 17 | 考虑到手机游戏项目的平台兼容性和效率要求,我们决定采用64位的迪菲-赫尔曼密钥交换算法,所以建立了这个代码仓库用来收集不同语言的算法实现。 18 | 19 | 用法 20 | ==== 21 | 22 | 随机生成一对64位密钥(私钥 + 公钥): 23 | 24 | ``` 25 | // C 26 | uint64_t my_private_key; 27 | uint64_t my_public_key; 28 | 29 | dh64_key_pair(&my_private_key, &my_public_key); 30 | 31 | // Go 32 | myPrivateKey, myPublicKey := dh64.KeyPair() 33 | 34 | // C# 35 | DH64 dh64 = new DH64(); 36 | 37 | ulong myPrivateKey; 38 | ulong myPublicKey; 39 | 40 | dh64.KeyPair(out myPrivateKey, out myPublicKey); 41 | ``` 42 | 43 | 用以上方式获得公钥之后,就可以通过网络把公钥传递给对方,双方互相拿到对方的公钥之后,利用自己手上的私钥和对方的公钥就可以计算出双方一致的密钥,这样就完成了密钥交换过程: 44 | 45 | ``` 46 | // C 47 | uint64_t secert = dh64_secert(my_private_key, another_publick_key); 48 | 49 | // Go 50 | secert := dh64.Secert(myPrivateKey, anotherPublicKey); 51 | 52 | // C# 53 | ulong secert = dh64.Secert(myPrivateKey, anotherPublicKey); 54 | ``` 55 | 56 | 最终这个密钥就可以用于RC4之类的加密算法来对双发的后续通讯内容做加密了。 57 | 58 | 进阶用法 59 | ======= 60 | 61 | 默认的生成方式使用的是语言内置的伪随机函数,如果要加强安全性可以自己用真随机来生成一个64位的私钥,然后单独生成DH64交换用的公钥: 62 | 63 | ``` 64 | // C 65 | uint64_t my_private_key = my_real_random64(); 66 | uint64_t my_public_key = dh64_public_key(my_private_key); 67 | 68 | // Go 69 | myPrivateKey := MyRealRandom64(); 70 | myPublicKey := dh64.PublicKey(myPrivateKey); 71 | 72 | // C# 73 | ulong myPrivateKey = MyRealRandom64(); 74 | ulong myPublicKey = dh64.PublicKey(myPrivateKey); 75 | ``` 76 | 77 | NOTE: 请注意自己生成私钥的时候,私钥必须大于等于1,这是DH算法要求的。 78 | 79 | 相关链接 80 | ======= 81 | 82 | 1. [迪菲-赫尔曼密钥交换](https://zh.wikipedia.org/wiki/%E8%BF%AA%E8%8F%B2%EF%BC%8D%E8%B5%AB%E5%B0%94%E6%9B%BC%E5%AF%86%E9%92%A5%E4%BA%A4%E6%8D%A2) 83 | 2. [云风开源的C版本代码](https://gist.github.com/cloudwu/8838724) 84 | 3. [DH64密钥交换 + RC4加密的演示](https://github.com/funny/crypto/tree/master/rc4) 85 | -------------------------------------------------------------------------------- /dh64/c/dh64.c: -------------------------------------------------------------------------------- 1 | // The biggest 64bit prime 2 | #define P 0xffffffffffffffc5ull 3 | #define G 5 4 | 5 | #include 6 | 7 | #include "dh64.h" 8 | 9 | // calc a * b % p , avoid 64bit overflow 10 | static inline uint64_t 11 | mul_mod_p(uint64_t a, uint64_t b) { 12 | uint64_t m = 0; 13 | while (b) { 14 | if (b&1) { 15 | uint64_t t = P - a; 16 | if (m >= t) { 17 | m -= t; 18 | } else { 19 | m += a; 20 | } 21 | } 22 | if (a >= P - a) { 23 | a = a * 2 - P; 24 | } else { 25 | a = a * 2; 26 | } 27 | b >>= 1; 28 | } 29 | return m; 30 | } 31 | 32 | static inline uint64_t 33 | pow_mod_p(uint64_t a, uint64_t b) { 34 | if (b == 1) { 35 | return a; 36 | } 37 | uint64_t t = pow_mod_p(a, b>>1); 38 | t = mul_mod_p(t, t); 39 | if (b % 2) { 40 | t = mul_mod_p(t, a); 41 | } 42 | return t; 43 | } 44 | 45 | // calc a^b % p 46 | static inline uint64_t 47 | powmodp(uint64_t a, uint64_t b) { 48 | if (a == 0) 49 | return 1; 50 | if (b == 0) 51 | return 1; 52 | if (a > P) 53 | a %= P; 54 | return pow_mod_p(a, b); 55 | } 56 | 57 | void 58 | dh64_key_pair(uint64_t* private_key, uint64_t* public_key) { 59 | uint64_t a = rand(); 60 | uint64_t b = rand() & 0xFFFF; 61 | uint64_t c = rand() & 0xFFFF; 62 | uint64_t d = (rand() & 0xFFFF) + 1; 63 | *private_key = a << 48 | b << 32 | c << 16 | d; 64 | *public_key = powmodp(G, *private_key); 65 | } 66 | 67 | uint64_t 68 | dh64_public_key(const uint64_t private_key) { 69 | return powmodp(G, private_key); 70 | } 71 | 72 | uint64_t 73 | dh64_secret(const uint64_t private_key, const uint64_t another_public_key) { 74 | return powmodp(another_public_key, private_key); 75 | } 76 | -------------------------------------------------------------------------------- /dh64/c/dh64.h: -------------------------------------------------------------------------------- 1 | #ifndef DH64_H 2 | #define DH64_H 3 | 4 | #include 5 | 6 | void dh64_key_pair(uint64_t* private_key, uint64_t* public_key); 7 | 8 | uint64_t dh64_public_key(const uint64_t private_key); 9 | 10 | uint64_t dh64_secret(const uint64_t private_key, const uint64_t another_public_key); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /dh64/c/dh64_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "dh64.h" 6 | 7 | // cc dh64.c dh64_test.c 8 | int main(int argc, char **argv) { 9 | int n = 10000; 10 | if (argc > 1) { 11 | n = atoi(argv[1]); 12 | } 13 | for (int i = 0; i < n; i ++) { 14 | uint64_t private_key1; 15 | uint64_t public_key1; 16 | dh64_key_pair(&private_key1, &public_key1); 17 | 18 | 19 | uint64_t private_key2; 20 | uint64_t public_key2; 21 | dh64_key_pair(&private_key2, &public_key2); 22 | 23 | uint64_t secret1 = dh64_secret(private_key1, public_key2); 24 | uint64_t secret2 = dh64_secret(private_key2, public_key1); 25 | 26 | assert(secret1 == secret2); 27 | printf("{0x%016llX, 0x%016llX, 0x%016llX},\n", public_key1, private_key1, secret1); 28 | printf("{0x%016llX, 0x%016llX, 0x%016llX},\n", public_key2, private_key2, secret2); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dh64/csharp/dh64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Funny.Crypto 4 | { 5 | public class DH64 6 | { 7 | private const ulong p = 0xffffffffffffffc5; 8 | private const ulong g = 5; 9 | 10 | private static ulong mul_mod_p(ulong a, ulong b) { 11 | ulong m = 0; 12 | while (b > 0) { 13 | if ((b&1) > 0) { 14 | var t = p - a; 15 | if (m >= t) { 16 | m -= t; 17 | } else { 18 | m += a; 19 | } 20 | } 21 | if (a >= p-a) { 22 | a = a*2 - p; 23 | } else { 24 | a = a * 2; 25 | } 26 | b >>= 1; 27 | } 28 | return m; 29 | } 30 | 31 | private static ulong pow_mod_p(ulong a, ulong b) { 32 | if (b == 1) { 33 | return a; 34 | } 35 | var t = pow_mod_p(a, b>>1); 36 | t = mul_mod_p(t, t); 37 | if ((b%2) > 0) { 38 | t = mul_mod_p(t, a); 39 | } 40 | return t; 41 | } 42 | 43 | private static ulong powmodp(ulong a , ulong b) { 44 | if (a == 0) { 45 | throw new Exception("DH64 zero public key"); 46 | } 47 | if (b == 0) { 48 | throw new Exception("DH64 zero private key"); 49 | } 50 | if (a > p) { 51 | a %= p; 52 | } 53 | return pow_mod_p(a, b); 54 | } 55 | 56 | private Random rand; 57 | 58 | public DH64() { 59 | rand = new Random(); 60 | } 61 | 62 | public void KeyPair(out ulong privateKey, out ulong publicKey) { 63 | var a = (ulong)rand.Next(); 64 | var b = (ulong)rand.Next() + 1; 65 | privateKey = (a<<32) | b; 66 | publicKey = PublicKey(privateKey); 67 | } 68 | 69 | public ulong PublicKey(ulong privateKey) { 70 | return powmodp(g, privateKey); 71 | } 72 | 73 | public ulong Secret(ulong privateKey, ulong anotherPublicKey) { 74 | return powmodp(anotherPublicKey, privateKey); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /dh64/go/dh64.go: -------------------------------------------------------------------------------- 1 | package dh64 2 | 3 | import ( 4 | "math/rand" 5 | ) 6 | 7 | const ( 8 | p uint64 = 0xffffffffffffffc5 9 | g uint64 = 5 10 | ) 11 | 12 | func mul_mod_p(a, b uint64) uint64 { 13 | var m uint64 = 0 14 | for b > 0 { 15 | if b&1 > 0 { 16 | t := p - a 17 | if m >= t { 18 | m -= t 19 | } else { 20 | m += a 21 | } 22 | } 23 | if a >= p-a { 24 | a = a*2 - p 25 | } else { 26 | a = a * 2 27 | } 28 | b >>= 1 29 | } 30 | return m 31 | } 32 | 33 | func pow_mod_p(a, b uint64) uint64 { 34 | if b == 1 { 35 | return a 36 | } 37 | t := pow_mod_p(a, b>>1) 38 | t = mul_mod_p(t, t) 39 | if b%2 > 0 { 40 | t = mul_mod_p(t, a) 41 | } 42 | return t 43 | } 44 | 45 | func powmodp(a uint64, b uint64) uint64 { 46 | if a == 0 { 47 | panic("DH64 zero public key") 48 | } 49 | if b == 0 { 50 | panic("DH64 zero private key") 51 | } 52 | if a > p { 53 | a %= p 54 | } 55 | return pow_mod_p(a, b) 56 | } 57 | 58 | func KeyPair() (privateKey, publicKey uint64) { 59 | a := uint64(rand.Uint32()) 60 | b := uint64(rand.Uint32()) + 1 61 | privateKey = (a << 32) | b 62 | publicKey = PublicKey(privateKey) 63 | return 64 | } 65 | 66 | func PublicKey(privateKey uint64) uint64 { 67 | return powmodp(g, privateKey) 68 | } 69 | 70 | func Secret(privateKey, anotherPublicKey uint64) uint64 { 71 | return powmodp(anotherPublicKey, privateKey) 72 | } 73 | -------------------------------------------------------------------------------- /mt19937/README.md: -------------------------------------------------------------------------------- 1 | MT19937-64伪随机算法代码集 2 | ===================== 3 | 4 | MT19937-64是`梅森旋转算法`的64位实现,通用于各种编程语言的伪随机数生成算法。 5 | 6 | 本代码仓库收集整理了不同语言的MT19937-64算法实现,并做了测试。 7 | 8 | 可以用于客户端运算服务端验证型的游戏项目。 9 | 10 | 由服务端下发随机种子,由于算法一致,所以客户端每次随机的结果都是服务端可验证的。 11 | 12 | 用法 13 | ==== 14 | 15 | 1. 对于Unity之类的C#项目,只需要把mt19937.cs文件放入项目中即可。 16 | 2. 对于Go语言项目,把go目录复制到项目中,更名为mt19937,使用import用法导入包。 17 | 18 | 相关链接 19 | ======= 20 | 21 | 1. [梅森旋转算法](http://zh.wikipedia.org/wiki/%E6%A2%85%E6%A3%AE%E6%97%8B%E8%BD%AC%E7%AE%97%E6%B3%95) 22 | 2. [C语言版的实现](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html) 23 | 3. [C#版本的实现](https://github.com/M-S-D/Team-Splitter/blob/master/mt19937.cs) 24 | 4. [Go语言版的实现](https://github.com/seehuhn/mt19937/blob/master/mt19937.go) 25 | 26 | 注1:C语言版默认是静态调用模式,本仓库收集整理时重构为实例化的方式调用。 27 | 28 | 注2:C#版实现用了静态写法,本仓库收集整理时重构了命名方式并改为非静态用法。 29 | 30 | 注3:Go语言版没有浮点数生成的部分,本仓库收集整理时添加了这部分代码。 31 | -------------------------------------------------------------------------------- /mt19937/c/mt19937-64.c: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937-64 (2014/2/23 version). 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | This is a 64-bit version of Mersenne Twister pseudorandom number 6 | generator. 7 | 8 | Before using, initialize the state by using init_genrand64(seed) 9 | or init_by_array64(init_key, key_length). 10 | 11 | Copyright (C) 2004, 2014, Makoto Matsumoto and Takuji Nishimura, 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions 16 | are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | 3. The names of its contributors may not be used to endorse or promote 26 | products derived from this software without specific prior written 27 | permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | 41 | References: 42 | T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' 43 | ACM Transactions on Modeling and 44 | Computer Simulation 10. (2000) 348--357. 45 | M. Matsumoto and T. Nishimura, 46 | ``Mersenne Twister: a 623-dimensionally equidistributed 47 | uniform pseudorandom number generator'' 48 | ACM Transactions on Modeling and 49 | Computer Simulation 8. (Jan. 1998) 3--30. 50 | 51 | Any feedback is very welcome. 52 | http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) 54 | */ 55 | 56 | 57 | #include 58 | #include 59 | #include "mt19937-64.h" 60 | 61 | mt19937* mt19937_new() { 62 | mt19937* mt = (mt19937*)calloc(1, sizeof(mt19937)); 63 | mt->mti = NN+1; 64 | return mt; 65 | } 66 | 67 | void mt19937_free(mt19937* this) { 68 | free(this); 69 | } 70 | 71 | /* initializes mt[NN] with a seed */ 72 | void mt19937_seed(mt19937* this, uint64_t seed) 73 | { 74 | int mti; 75 | uint64_t* mt = this->mt; 76 | 77 | mt[0] = seed; 78 | for (mti=1; mti> 62)) + mti); 80 | 81 | this->mti = mti; 82 | } 83 | 84 | /* initialize by an array with array-length */ 85 | /* init_key is the array for initializing keys */ 86 | /* key_length is its length */ 87 | void mt19937_seed_by_array(mt19937* this, uint64_t init_key[], uint64_t key_length) 88 | { 89 | unsigned int i, j; 90 | uint64_t k; 91 | uint64_t* mt = this->mt; 92 | mt19937_seed(this, UINT64_C(19650218)); 93 | i=1; j=0; 94 | k = (NN>key_length ? NN : key_length); 95 | for (; k; k--) { 96 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * UINT64_C(3935559000370003845))) 97 | + init_key[j] + j; /* non linear */ 98 | i++; j++; 99 | if (i>=NN) { mt[0] = mt[NN-1]; i=1; } 100 | if (j>=key_length) j=0; 101 | } 102 | for (k=NN-1; k; k--) { 103 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * UINT64_C(2862933555777941757))) 104 | - i; /* non linear */ 105 | i++; 106 | if (i>=NN) { mt[0] = mt[NN-1]; i=1; } 107 | } 108 | 109 | mt[0] = UINT64_C(1) << 63; /* MSB is 1; assuring non-zero initial array */ 110 | } 111 | 112 | static uint64_t mag01[2]={UINT64_C(0), MATRIX_A}; 113 | 114 | /* generates a random number on [0, 2^64-1]-interval */ 115 | uint64_t mt19937_uint64(mt19937* this) 116 | { 117 | int i; 118 | uint64_t x; 119 | 120 | int mti = this->mti; 121 | uint64_t* mt = this->mt; 122 | 123 | if (mti >= NN) { /* generate NN words at one time */ 124 | 125 | /* if init_genrand64() has not been called, */ 126 | /* a default initial seed is used */ 127 | if (mti == NN+1) { 128 | mt19937_seed(this, UINT64_C(5489)); 129 | mti = this->mti; 130 | } 131 | 132 | for (i=0;i>1) ^ mag01[(int)(x&UINT64_C(1))]; 135 | } 136 | for (;i>1) ^ mag01[(int)(x&UINT64_C(1))]; 139 | } 140 | x = (mt[NN-1]&UM)|(mt[0]&LM); 141 | mt[NN-1] = mt[MM-1] ^ (x>>1) ^ mag01[(int)(x&UINT64_C(1))]; 142 | 143 | mti = 0; 144 | } 145 | 146 | x = mt[mti++]; 147 | 148 | x ^= (x >> 29) & UINT64_C(0x5555555555555555); 149 | x ^= (x << 17) & UINT64_C(0x71D67FFFEDA60000); 150 | x ^= (x << 37) & UINT64_C(0xFFF7EEE000000000); 151 | x ^= (x >> 43); 152 | 153 | this->mti = mti; 154 | 155 | return x; 156 | } 157 | 158 | /* generates a random number on [0, 2^63-1]-interval */ 159 | int64_t mt19937_int63(mt19937* this) 160 | { 161 | return (int64_t)(mt19937_uint64(this) >> 1); 162 | } 163 | 164 | /* generates a random number on [0,1]-real-interval */ 165 | double mt19937_real1(mt19937* this) 166 | { 167 | return (mt19937_uint64(this) >> 11) * (1.0/9007199254740991.0); 168 | } 169 | 170 | /* generates a random number on [0,1)-real-interval */ 171 | double mt19937_real2(mt19937* this) 172 | { 173 | return (mt19937_uint64(this) >> 11) * (1.0/9007199254740992.0); 174 | } 175 | 176 | /* generates a random number on (0,1)-real-interval */ 177 | double mt19937_real3(mt19937* this) 178 | { 179 | return ((mt19937_uint64(this) >> 12) + 0.5) * (1.0/4503599627370496.0); 180 | } 181 | -------------------------------------------------------------------------------- /mt19937/c/mt19937-64.h: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937-64 (2014/2/23 version). 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | This is a 64-bit version of Mersenne Twister pseudorandom number 6 | generator. 7 | 8 | Before using, initialize the state by using init_genrand64(seed) 9 | or init_by_array64(init_key, key_length). 10 | 11 | Copyright (C) 2004, 2014, Makoto Matsumoto and Takuji Nishimura, 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions 16 | are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | 3. The names of its contributors may not be used to endorse or promote 26 | products derived from this software without specific prior written 27 | permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | 41 | References: 42 | T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' 43 | ACM Transactions on Modeling and 44 | Computer Simulation 10. (2000) 348--357. 45 | M. Matsumoto and T. Nishimura, 46 | ``Mersenne Twister: a 623-dimensionally equidistributed 47 | uniform pseudorandom number generator'' 48 | ACM Transactions on Modeling and 49 | Computer Simulation 8. (Jan. 1998) 3--30. 50 | 51 | Any feedback is very welcome. 52 | http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) 54 | */ 55 | 56 | #include 57 | 58 | #define NN 312 59 | #define MM 156 60 | #define MATRIX_A UINT64_C(0xB5026F5AA96619E9) 61 | #define UM UINT64_C(0xFFFFFFFF80000000) /* Most significant 33 bits */ 62 | #define LM UINT64_C(0x7FFFFFFF) /* Least significant 31 bits */ 63 | 64 | typedef struct mt19937 { 65 | /* The array for the state vector */ 66 | uint64_t mt[NN]; 67 | /* mti==NN+1 means mt[NN] is not initialized */ 68 | int mti; 69 | } mt19937; 70 | 71 | mt19937* mt19937_new(); 72 | void mt19937_free(mt19937* this); 73 | 74 | /* initializes mt[NN] with a seed */ 75 | void mt19937_seed(mt19937* this, uint64_t seed); 76 | 77 | /* initialize by an array with array-length */ 78 | /* init_key is the array for initializing keys */ 79 | /* key_length is its length */ 80 | void mt19937_seed_by_array(mt19937* this, uint64_t init_key[], uint64_t key_length); 81 | 82 | /* generates a random number on [0, 2^64-1]-interval */ 83 | uint64_t mt19937_uint64(mt19937*); 84 | 85 | 86 | /* generates a random number on [0, 2^63-1]-interval */ 87 | int64_t mt19937_int63(mt19937*); 88 | 89 | /* generates a random number on [0,1]-real-interval */ 90 | double mt19937_real1(mt19937*); 91 | 92 | /* generates a random number on [0,1)-real-interval */ 93 | double mt19937_real2(mt19937*); 94 | 95 | /* generates a random number on (0,1)-real-interval */ 96 | double mt19937_real3(mt19937*); 97 | -------------------------------------------------------------------------------- /mt19937/c/mt19937-64.out.txt: -------------------------------------------------------------------------------- 1 | 7266447313870364031 4946485549665804864 16945909448695747420 16394063075524226720 4873882236456199058 2 | 14877448043947020171 6740343660852211943 13857871200353263164 5249110015610582907 10205081126064480383 3 | 1235879089597390050 17320312680810499042 16489141110565194782 8942268601720066061 13520575722002588570 4 | 14226945236717732373 9383926873555417063 15690281668532552105 11510704754157191257 15864264574919463609 5 | 6489677788245343319 5112602299894754389 10828930062652518694 15942305434158995996 15445717675088218264 6 | 4764500002345775851 14673753115101942098 236502320419669032 13670483975188204088 14931360615268175698 7 | 8904234204977263924 12836915408046564963 12120302420213647524 15755110976537356441 5405758943702519480 8 | 10951858968426898805 17251681303478610375 4144140664012008120 18286145806977825275 13075804672185204371 9 | 10831805955733617705 6172975950399619139 12837097014497293886 12903857913610213846 560691676108914154 10 | 1074659097419704618 14266121283820281686 11696403736022963346 13383246710985227247 7132746073714321322 11 | 10608108217231874211 9027884570906061560 12893913769120703138 15675160838921962454 2511068401785704737 12 | 14483183001716371453 3774730664208216065 5083371700846102796 9583498264570933637 17119870085051257224 13 | 5217910858257235075 10612176809475689857 1924700483125896976 7171619684536160599 10949279256701751503 14 | 15596196964072664893 14097948002655599357 615821766635933047 5636498760852923045 17618792803942051220 15 | 580805356741162327 425267967796817241 8381470634608387938 13212228678420887626 16993060308636741960 16 | 957923366004347591 6210242862396777185 1012818702180800310 15299383925974515757 17501832009465945633 17 | 17453794942891241229 15807805462076484491 8407189590930420827 974125122787311712 1861591264068118966 18 | 997568339582634050 18046771844467391493 17981867688435687790 3809841506498447207 9460108917638135678 19 | 16172980638639374310 958022432077424298 4393365126459778813 13408683141069553686 13900005529547645957 20 | 15773550354402817866 16475327524349230602 6260298154874769264 12224576659776460914 6405294864092763507 21 | 7585484664713203306 5187641382818981381 12435998400285353380 13554353441017344755 646091557254529188 22 | 11393747116974949255 16797249248413342857 15713519023537495495 12823504709579858843 4738086532119935073 23 | 4429068783387643752 585582692562183870 1048280754023674130 6788940719869959076 11670856244972073775 24 | 2488756775360218862 2061695363573180185 6884655301895085032 3566345954323888697 12784319933059041817 25 | 4772468691551857254 6864898938209826895 7198730565322227090 2452224231472687253 13424792606032445807 26 | 10827695224855383989 11016608897122070904 14683280565151378358 7077866519618824360 17487079941198422333 27 | 3956319990205097495 5804870313319323478 8017203611194497730 3310931575584983808 5009341981771541845 28 | 6930001938490791874 14415278059151389495 11001114762641844083 6715939435439735925 411419160297131328 29 | 4522402260441335284 3381955501804126859 15935778656111987797 4345051260540166684 13978444093099579683 30 | 9219789505504949817 9245142924137529075 11628184459157386459 7242398879359936370 8511401943157540109 31 | 11948130810477009827 6865450671488705049 13965005347172621081 15956599226522058336 7737868921014130584 32 | 2107342503741411693 15818996300425101108 16399939197527488760 13971145494081508107 3910681448359868691 33 | 4249175367970221090 9735751321242454020 12418107929362160460 241792245481991138 5806488997649497146 34 | 10724207982663648949 1121862814449214435 1326996977123564236 4902706567834759475 12782714623891689967 35 | 7306216312942796257 15681656478863766664 957364844878149318 5651946387216554503 8197027112357634782 36 | 6302075516351125977 13454588464089597862 15638309200463515550 10116604639722073476 12052913535387714920 37 | 2889379661594013754 15383926144832314187 7841953313015471731 17310575136995821873 9820021961316981626 38 | 15319619724109527290 15349724127275899898 10511508162402504492 6289553862380300393 15046218882019267110 39 | 11772020174577005930 3537640779967351792 6801855569284252424 17687268231192623388 12968358613633237218 40 | 1429775571144180123 10427377732172208413 12155566091986788996 16465954421598296115 12710429690464359999 41 | 9547226351541565595 12156624891403410342 2985938688676214686 18066917785985010959 5975570403614438776 42 | 11541343163022500560 11115388652389704592 9499328389494710074 9247163036769651820 3688303938005101774 43 | 2210483654336887556 15458161910089693228 6558785204455557683 1288373156735958118 18433986059948829624 44 | 3435082195390932486 16822351800343061990 3120532877336962310 16681785111062885568 7835551710041302304 45 | 2612798015018627203 15083279177152657491 6591467229462292195 10592706450534565444 7438147750787157163 46 | 323186165595851698 7444710627467609883 8473714411329896576 2782675857700189492 3383567662400128329 47 | 3200233909833521327 12897601280285604448 3612068790453735040 8324209243736219497 15789570356497723463 48 | 1083312926512215996 4797349136059339390 5556729349871544986 18266943104929747076 1620389818516182276 49 | 172225355691600141 3034352936522087096 1266779576738385285 3906668377244742888 6961783143042492788 50 | 17159706887321247572 4676208075243319061 10315634697142985816 13435140047933251189 716076639492622016 51 | 13847954035438697558 7195811275139178570 10815312636510328870 6214164734784158515 16412194511839921544 52 | 3862249798930641332 1005482699535576005 4644542796609371301 17600091057367987283 4209958422564632034 53 | 5419285945389823940 11453701547564354601 9951588026679380114 7425168333159839689 8436306210125134906 54 | 11216615872596820107 3681345096403933680 5770016989916553752 11102855936150871733 11187980892339693935 55 | 396336430216428875 6384853777489155236 7551613839184151117 16527062023276943109 13429850429024956898 56 | 9901753960477271766 9731501992702612259 5217575797614661659 10311708346636548706 15111747519735330483 57 | 4353415295139137513 1845293119018433391 11952006873430493561 3531972641585683893 16852246477648409827 58 | 15956854822143321380 12314609993579474774 16763911684844598963 16392145690385382634 1545507136970403756 59 | 17771199061862790062 12121348462972638971 12613068545148305776 954203144844315208 1257976447679270605 60 | 3664184785462160180 2747964788443845091 15895917007470512307 15552935765724302120 16366915862261682626 61 | 8385468783684865323 10745343827145102946 2485742734157099909 916246281077683950 15214206653637466707 62 | 12895483149474345798 1079510114301747843 10718876134480663664 1259990987526807294 8326303777037206221 63 | 14104661172014248293 15531278677382192198 3874303698666230242 3611366553819264523 1358753803061653874 64 | 1552102816982246938 14492630642488100979 15001394966632908727 2273140352787320862 17843678642369606172 65 | 2903980458593894032 16971437123015263604 12969653681729206264 3593636458822318001 9719758956915223015 66 | 7437601263394568346 3327758049015164431 17851524109089292731 14769614194455139039 8017093497335662337 67 | 12026985381690317404 739616144640253634 15535375191850690266 2418267053891303448 15314073759564095878 68 | 10333316143274529509 16565481511572123421 16317667579273275294 13991958187675987741 3753596784796798785 69 | 9078249094693663275 8459506356724650587 12579909555010529099 7827737296967050903 5489801927693999341 70 | 10995988997350541459 14721747867313883304 7915884580303296560 4105766302083365910 12455549072515054554 71 | 13602111324515032467 5205971628932290989 5034622965420036444 9134927878875794005 11319873529597990213 72 | 14815445109496752058 2266601052460299470 5696993487088103383 6540200741841280242 6631495948031875490 73 | 5328340585170897740 17897267040961463930 9030000260502624168 14285709137129830926 12854071997824681544 74 | 15408328651008978682 1063314403033437073 13765209628446252802 242013711116865605 4772374239432528212 75 | 2515855479965038648 5872624715703151235 14237704570091006662 678604024776645862 12329607334079533339 76 | 17570877682732917020 2695443415284373666 4312672841405514468 6454343485137106900 8425658828390111343 77 | 16335501385875554899 5551095603809016713 11781094401885925035 9395557946368382509 9765123360948816956 78 | 18107191819981188154 16049267500594757404 16349966108299794199 1040405303135858246 2366386386131378192 79 | 223761048139910454 15375217587047847934 15231693398695187454 12916726640254571028 8878036960829635584 80 | 1626201782473074365 5758998126998248293 18077917959300292758 10585588923088536745 15072345664541731497 81 | 3559348759319842667 12744591691872202375 2388494115860283059 6414691845696331748 3069528498807764495 82 | 8737958486926519702 18059264986425101074 3139684427605102737 12378931902986734693 410666675039477949 83 | 12139894855769838924 5780722552400398675 7039346665375142557 3020733445712569008 2612305843503943561 84 | 13651771214166527665 16478681918975800939 566088527565499576 4715785502295754870 6957318344287196220 85 | 11645756868405128885 13139951104358618000 17650948583490040612 18168787973649736637 5486282999836125542 86 | 6122201977153895166 17324241605502052782 10063523107521105867 17537430712468011382 10828407533637104262 87 | 10294139354198325113 12557151830240236401 16673044307512640231 10918020421896090419 11077531235278014145 88 | 5499571814940871256 2334252435740638702 18177461912527387031 2000007376901262542 7968425560071444214 89 | 1472650787501520648 3115849849651526279 7980970700139577536 12153253535907642097 8109716914843248719 90 | 3154976533165008908 5553369513523832559 10345792701798576501 3677445364544507875 10637177623943913351 91 | 7380255087060498096 14479400372337014801 15381362583330700960 204531043189704802 13699106540959723942 92 | 3817903465872254783 10972364467110284934 2701394334530963810 2931625600749229147 16428252083632828910 93 | 11873166501966812913 5566810080537233762 7840617383807795056 10699413880206684652 18259119259617231436 94 | 10332714341486317526 10137911902863059694 669146221352346842 8373571610024623455 10620002450820868661 95 | 12220730820779815970 5902974968095412898 7931010481705150841 16413777368097063650 11273457888324769727 96 | 13719113891065284171 8327795098009702553 10333342364827584837 6202832891413866653 9137034567886143162 97 | 14514450826524340059 473610156015331016 813689571029117640 13776316799690285717 10429708855338427756 98 | 8995290140880620858 2320123852041754384 8082864073645003641 6961777411740398590 10008644283003991179 99 | 3239064015890722333 16762634970725218787 16467281536733948427 10563290046315192938 5108560603794851559 100 | 15121667220761532906 14155440077372845941 10050536352394623377 15474881667376037792 3448088038819200619 101 | 3692020001240358871 6444847992258394902 8687650838094264665 3028124591188972359 16945232313401161629 102 | 15547830510283682816 3982930188609442149 14270781928849894661 13768475593433447867 13815150225221307677 103 | 8502397232429564693 718377350715476994 7459266877697905475 8353375565171101521 7807281661994435472 104 | 16924127046922196149 10157812396471387805 2519858716882670232 7384148884750265792 8077153156180046901 105 | 3499231286164597752 2700106282881469611 14679824700835879737 14188324938219126828 3016120398601032793 106 | 10858152824243889420 9412371965669250534 4857522662584941069 984331743838900386 4094160040294753142 107 | 2368635764350388458 15101240511397838657 15584415763303953578 7831857200208015446 1952643641639729063 108 | 4184323302594028609 16795120381104846695 3541559381538365280 15408472870896842474 5628362450757896366 109 | 16277348886873708846 12437047172652330846 10172715019035948149 1999700669649752791 6217957085626135027 110 | 11220551167830336823 16478747645632411810 5437280487207382147 11382378739613087836 15866932785489521505 111 | 5502694314775516684 16440179278067648435 15510104554374162846 15722061259110909195 10760687291786964354 112 | 10736868329920212671 4166148127664495614 14303518358120527892 9122250801678898571 10028508179936801946 113 | 216630713752669403 10655207865433859491 4041437116174699233 6280982262534375348 297501356638818866 114 | 13976146806363377485 13752396481560145603 11472199956603637419 16393728429143900496 14752844047515986640 115 | 1524477318846038424 6596889774254235440 1591982099532234960 8065146456116391065 3964696017750868345 116 | 17040425970526664920 11511165586176539991 3443401252003315103 16314977947073778249 16860120454903458341 117 | 5370503221561340846 15362920279125264094 2822458124714999779 14575378304387898337 9689406052675046032 118 | 2872149351415175149 13019620945255883050 14929026760148695825 8503417349692327218 9677798905341573754 119 | 828949921821462483 16110482368362750196 15794218816553655671 14942910774764855088 12026350906243760195 120 | 13610867176871462505 18324536557697872582 2658962269666727629 327225403251576027 9207535177029277544 121 | 8744129291351887858 6129603385168921503 18385497655031085907 13024478718952333892 14547683159720717167 122 | 5932119629366981711 325385464632594563 3559879386019806291 6629264948665231298 14358245326238118181 123 | 15662449672706340765 13975503159145803297 3609534220891499022 4224273587485638227 9274084767162416370 124 | 13156843921244091998 18284750575626858789 14664767920489118779 11292057742031803221 13919998707305829132 125 | 14473305049457001422 9696877879685767807 1406758246007973837 2429517644459056881 14361215588101587430 126 | 11386164476149757528 10474116023593331839 2921165656527786564 15604610369733358953 12955027028676000544 127 | 10314281035410779907 3167047178514709947 1088721329408346700 17930425515478182741 7466411836095405617 128 | 15534027454610690575 10879629128927506091 11502219301371200635 13915106894453889418 4226784327815861027 129 | 12335222183627106346 3648499746356007767 18441388887898023393 18117929843327093625 4237736098094830438 130 | 14229123019768296655 3930112058127932690 12663879236019645778 9281161952002617309 4978473890680876319 131 | 845759387067546611 1386164484606776333 8008554770639925512 11159581016793288971 18065390393740782906 132 | 17647985458967631018 9092379465737744314 2914678236848656327 4376066698447630270 16057186499919087528 133 | 3031333261848790078 2926746602873431597 7931945763526885287 147649915388326849 15801792398814946230 134 | 5265900391686545347 16173686275871890830 7562781050481886043 5853506575839330404 14957980734704564792 135 | 10944286556353523404 1783009880614150597 9529762028588888983 822992871011696119 2130074274744257510 136 | 8000279549284809219 3514744284158856431 128770032569293263 3737367602618100572 16364836605077998543 137 | 783266423471782696 4569418252658970391 11093950688157406886 14888808512267628166 4217786261273670948 138 | 17047486076688645713 14133826721458860485 17539744882220127106 12394675039129853905 5757634999463277090 139 | 9621947619435861331 1182210208559436772 14603391040490913939 17481976703660945893 14063388816234683976 140 | 2046622692581829572 8294969799792017441 5293778434844788058 17976364049306763808 399482430848083948 141 | 16495545010129798933 15241340958282367519 989828753826900814 17616558773874893537 2471817920909589004 142 | 11764082277667899978 9618755269550400950 1240014743757147125 1887649378641563002 1842982574728131416 143 | 13243531042427194002 7688268125537013927 3080422097287486736 2562894809975407783 12428984115620094788 144 | 1355581933694478148 9895969242586224966 8628445623963160889 4298916726468199239 12773165416305557280 145 | 5240726258301567487 4975412836403427561 1842172398579595303 7812151462958058676 17974510987263071769 146 | 14980707022065991200 18294903201142729875 12911672684850242753 8979482998667235743 16808468362384462073 147 | 5981317232108359798 12373702800369335100 16119707581920094765 2782738549717633602 15454155188515389391 148 | 16495638000603654629 16348757069342790497 7769562861984504567 17504300515449231559 5557710032938318996 149 | 11846125204788401203 13957316349928882624 2738350683717432043 15738068448047700954 6224714837294524999 150 | 6081930777706411111 11366312928059597928 4355315799925031482 12393324728734964015 15277140291994338591 151 | 1406052433297386355 15859448364509213398 1672805458341158435 2926095111610982994 11056431822276774455 152 | 12083767323511977430 3296968762229741153 12312076899982286460 17769284994682227273 15349428916826953443 153 | 1056147296359223910 18305757538706977431 6214378374180465222 14279648441175008454 17791306410319136644 154 | 956593013486324072 2921235772936241950 10002890515925652606 10399654693663712506 6446247931049971441 155 | 6380465770144534958 11439178472613251620 10131486500045494660 3692642123868351947 10972816599561388940 156 | 4931112976348785580 8213967169213816566 15336469859637867841 15026830342847689383 7524668622380765825 157 | 17309937346758783807 372780684412666438 5642417144539399955 18303842993081194577 11085303253831702827 158 | 15658163165983586950 8517521928922081563 16091186344159989860 17614656488010863910 4736067146481515156 159 | 13449945221374241354 17755469346196579408 13300502638545717375 6611828134763118043 14177591906740276597 160 | 9340430243077460347 7499765399826404087 3409518087967832469 9013253864026602045 4444307427984430192 161 | 3729283608700519712 13642048880719588383 16486557958022946240 2996465014991157904 10020049344596426576 162 | 12302485648009883778 8492591321344423126 17407986443716172520 10530482934957373052 15740662350540828750 163 | 1790629986901049436 6305948377669917188 15092985352503125323 928505047232899787 14404651977039851607 164 | 7564177565277805597 3411236815351677870 7752718145953236134 12315979971311483798 12477729506691004724 165 | 14654956300924793305 6689803038918974388 1540738812233000153 13508351811701989957 15864432023192136053 166 | 7990997967273843917 7424300239290765161 39585249496300263 3877436595063283319 10710642254398044448 167 | 4653804418844456375 1232267496410380283 3690525514009038824 15459770765077428485 13240346522153894145 168 | 5674964360688390624 16973644653010587289 15924280764204855206 15196708627253442662 17596174821341373274 169 | 16196745023027393691 6980050627399795351 17582264380857746637 18170372407506856324 12108126025631005514 170 | 15687749089493373169 5814107289258228434 9381977959648494876 15895601183088112734 16267869075651604263 171 | 15228381979765852785 11949618678312581999 4545324791131029438 582725409406225185 15282520250746126790 172 | 14758446535973412711 7605613563088071833 1111140641057375915 5364843095234852245 218335432181198977 173 | 4891472444796201742 4564628942836375772 15500501278323817088 4913946328556108657 2684786251736694229 174 | 12090498456116310122 5310885782157038567 5032788439854011923 12627401038822728242 11869662610126430929 175 | 17650156853043540226 12126672500118808436 10437658933435653256 13133995470637873311 4601324715591152820 176 | 1874350460376708372 5808688626286061164 13777088437302430376 5018451954762213522 2588296738534474754 177 | 5503414509154170711 5230497186769951796 13261090710400573914 8515217303152165705 11074538219737365303 178 | 15481562385740613213 12705484409881007350 14221931471178549498 12905633420087112297 17337759164357146506 179 | 14081997515778175224 17384320185513122939 7131793076779216692 17483217190312403109 900692047897995877 180 | 14723287313048560400 6132094372965340305 7572797575350925726 12725160700431903514 380860122911632449 181 | 1900504978569024571 8423729759529914138 7305587201606052334 12446871355267313320 4615812356515386206 182 | 3361817115406652303 17690418922000878428 14632214537567910559 2709702289926174775 3459675155951086144 183 | 7788364399926538150 16043992474431955950 15830963823784930267 4216893617835797954 538159724689093771 184 | 16029152738918251363 14444848757576686696 12941757045272633696 10900480525147953314 12547307449905859302 185 | 16001571796892398181 407942194622690676 13873235372903944444 18071603799493008777 1015646077646778622 186 | 9387605808959554815 11566702442022019410 7061722181092883183 2629032108249254109 5271820053177594520 187 | 12640880742139693547 10098688629735675775 5716304472850923064 3312674502353063071 7295926377425759633 188 | 833281439103466115 16316743519466861667 9912050326606348167 11651133878100804242 18026798122431692459 189 | 6157758321723692663 4856021830695749349 7074321707293278978 10748097797809573561 2949954440753264783 190 | 9813922580940661152 9949237950172138336 15643982711269455885 16078663425810239127 12508044395364228880 191 | 12920301578340189344 15368071871011048915 1610400750626363239 11994736084146033126 6042574085746186088 192 | 4154587549267685807 15915752367312946034 1191196620621769193 467437822242538360 2836463788873877488 193 | 10476401302029164984 1716169985450737419 5327734953288310341 3994170067185955262 884431883768190063 194 | 11019001754831208284 14322807384384895215 161011537360955545 1466223959660131656 5227048585229497539 195 | 12410731857504225031 2142243279080761103 17682826799106851430 1792612570704179953 14727410295243056025 196 | 1459567192481221274 5669760721687603135 17507918443756456845 10354471145847018200 10362475129248202288 197 | 13143844410150939443 6861184673150072028 18396524361124732580 543906666394301875 12476817828199026728 198 | 11853496871128122868 12747674713108891748 7986179867749890282 9158195177777627533 2217320706811118570 199 | 8631389005200569973 5538133061362648855 3369942850878700758 7813559982698427184 509051590411815948 200 | 10197035660403006684 13004818533162292132 9831652587047067687 7619315254749630976 994412663058993407 201 | 202 | 0.35252031 0.51052342 0.79771733 0.39300273 0.27216673 203 | 0.72151068 0.43144703 0.38522290 0.20270676 0.58227313 204 | 0.80812143 0.83767297 0.92401619 0.84065425 0.00852052 205 | 0.13975395 0.35250930 0.71196972 0.14627395 0.17775331 206 | 0.61046382 0.49623272 0.23292425 0.25038837 0.04380664 207 | 0.43275994 0.74540936 0.33830700 0.68832616 0.68744230 208 | 0.63626548 0.85932936 0.37089670 0.50756304 0.69925960 209 | 0.83481025 0.09053196 0.09523253 0.17783108 0.78027239 210 | 0.70071054 0.51879252 0.83027285 0.92895011 0.72144803 211 | 0.18868644 0.83655674 0.20358945 0.99852143 0.88340103 212 | 0.46729949 0.96993433 0.00162682 0.46829774 0.59080423 213 | 0.54921999 0.42516462 0.54952196 0.99534722 0.04473888 214 | 0.71139235 0.91881407 0.33781561 0.45746234 0.78292126 215 | 0.69206723 0.66175448 0.07091147 0.18179208 0.38168454 216 | 0.38819527 0.42452711 0.22732724 0.16191307 0.36842667 217 | 0.13060083 0.68833248 0.60498705 0.19195304 0.26628584 218 | 0.17030858 0.23892426 0.38430236 0.28034283 0.76069020 219 | 0.21560653 0.78101667 0.90847812 0.06467974 0.18487868 220 | 0.23570471 0.29475460 0.65563767 0.10066446 0.57272419 221 | 0.88731391 0.60650995 0.96346079 0.32940100 0.29977746 222 | 0.03798193 0.18026822 0.22402746 0.45480119 0.98114604 223 | 0.25800668 0.94362433 0.17901062 0.36019313 0.45933644 224 | 0.68309457 0.28175454 0.00774729 0.77054527 0.99723413 225 | 0.59807532 0.10294164 0.32429228 0.54928986 0.18410980 226 | 0.08441555 0.14230333 0.58892064 0.94030475 0.35378784 227 | 0.77584320 0.71222448 0.83565208 0.47309248 0.23810761 228 | 0.74408520 0.08891527 0.09729786 0.38377368 0.05092308 229 | 0.69065638 0.10449489 0.45050670 0.92209534 0.80083714 230 | 0.27902692 0.26897142 0.50650468 0.80111472 0.54590012 231 | 0.96406097 0.63779553 0.81054357 0.75369248 0.47473037 232 | 0.89100315 0.89395984 0.09985519 0.34087631 0.22293557 233 | 0.24375510 0.31764191 0.04076993 0.06160830 0.41333434 234 | 0.11883030 0.04548820 0.01008040 0.25336184 0.07325432 235 | 0.49860151 0.07148695 0.89483338 0.87054457 0.15116809 236 | 0.59650469 0.47487776 0.43490298 0.36684681 0.16470796 237 | 0.76865078 0.42920071 0.20545481 0.87615922 0.80332404 238 | 0.36462506 0.49571309 0.51904488 0.15534589 0.43719893 239 | 0.16562157 0.37290862 0.91842631 0.21310523 0.87849154 240 | 0.18532269 0.81713354 0.52182344 0.51845619 0.96261204 241 | 0.18758718 0.68897600 0.61484764 0.46752993 0.05865458 242 | 0.11614359 0.90386866 0.45781805 0.70649579 0.50917048 243 | 0.21210656 0.97818608 0.00788342 0.61375222 0.67366318 244 | 0.24197878 0.66177985 0.10463932 0.67390799 0.50025262 245 | 0.88332650 0.77966851 0.13403622 0.54357114 0.97664854 246 | 0.06540961 0.24013176 0.67234032 0.91347883 0.35486839 247 | 0.87207865 0.43036581 0.23652488 0.81238450 0.72058432 248 | 0.42239916 0.80265764 0.03552838 0.61939480 0.50972420 249 | 0.21053832 0.59952743 0.36821802 0.45659617 0.12529468 250 | 0.76941623 0.99878168 0.08602783 0.81825937 0.39350710 251 | 0.86090923 0.36090230 0.75628888 0.45036982 0.44602266 252 | 0.20595631 0.62241953 0.36777732 0.47523727 0.50248178 253 | 0.73570362 0.48237781 0.45590948 0.73580783 0.96403851 254 | 0.94586342 0.48819868 0.48102038 0.94618182 0.90279924 255 | 0.78396650 0.85182389 0.92149394 0.32679198 0.83554856 256 | 0.28320609 0.34598409 0.82090005 0.40177958 0.38888785 257 | 0.77873931 0.23297931 0.75329335 0.30770340 0.71417540 258 | 0.68939065 0.36577776 0.50784857 0.50928090 0.02552055 259 | 0.85999075 0.26692089 0.01402799 0.67550392 0.48305605 260 | 0.74608351 0.63408891 0.58904230 0.44337996 0.42174728 261 | 0.74041679 0.72719148 0.19801992 0.66263633 0.10381594 262 | 0.32818760 0.68369661 0.56076212 0.68681921 0.91616269 263 | 0.39836106 0.39685027 0.97507945 0.91010563 0.27447360 264 | 0.95538357 0.76758522 0.60091060 0.37734461 0.82948248 265 | 0.06598078 0.50147615 0.08417763 0.18910044 0.51661735 266 | 0.55011011 0.64888175 0.82986845 0.15126656 0.92649390 267 | 0.25494941 0.73275293 0.94184393 0.84755226 0.45921936 268 | 0.72934054 0.43722403 0.34305596 0.10827860 0.29026676 269 | 0.01935431 0.46668573 0.83247509 0.26349603 0.01938542 270 | 0.43222250 0.18109983 0.29337450 0.16721917 0.94751650 271 | 0.67795254 0.56666228 0.20699452 0.23247262 0.19138610 272 | 0.73495506 0.85893600 0.83411526 0.93689655 0.91804752 273 | 0.99352333 0.03207550 0.28386071 0.48029543 0.18736013 274 | 0.31736452 0.72542230 0.57530912 0.04229918 0.84798296 275 | 0.21886935 0.98655615 0.52243102 0.22611020 0.42975741 276 | 0.21726739 0.10912048 0.96684473 0.01092456 0.12461901 277 | 0.57989070 0.39848707 0.06330277 0.62826828 0.01159081 278 | 0.23157320 0.64690912 0.44876902 0.04463930 0.18933780 279 | 0.21284518 0.61363480 0.67144845 0.38625586 0.75719122 280 | 0.40361050 0.26708873 0.54534727 0.90174015 0.58654140 281 | 0.44885346 0.35505544 0.65317830 0.26074572 0.39472912 282 | 0.54366914 0.75020660 0.76113614 0.24595582 0.03941247 283 | 0.60356153 0.23615721 0.01603475 0.72432457 0.39837424 284 | 0.04195329 0.81561058 0.34208440 0.00513953 0.92826234 285 | 0.11410393 0.86692030 0.25238726 0.98258626 0.53353856 286 | 0.72269001 0.71850984 0.66829681 0.03540769 0.01676450 287 | 0.23557835 0.78758497 0.85969589 0.14673207 0.28013860 288 | 0.17796942 0.69924087 0.44663597 0.62112513 0.44079883 289 | 0.48995231 0.18411497 0.18440877 0.74016388 0.28845694 290 | 0.22969080 0.76851164 0.15551473 0.28980810 0.40906710 291 | 0.47619039 0.72611392 0.55802939 0.69365597 0.85736313 292 | 0.83343150 0.21324760 0.45327806 0.33053855 0.98198279 293 | 0.53279389 0.76877035 0.20548656 0.37065042 0.59026910 294 | 0.67418036 0.23585843 0.98156397 0.27849804 0.56198954 295 | 0.68752287 0.30073445 0.69348664 0.72515585 0.40629047 296 | 0.09320027 0.24334978 0.91407662 0.97226538 0.33904970 297 | 0.01717092 0.60155725 0.03001652 0.50979706 0.80531036 298 | 0.17450719 0.84984399 0.00498130 0.51636405 0.14080868 299 | 0.62289701 0.07853030 0.70567541 0.79844050 0.63766566 300 | 0.03559031 0.40994535 0.08423996 0.00389626 0.50608347 301 | 0.19622681 0.90537903 0.75458034 0.75102094 0.81491673 302 | 0.92925931 0.38074332 0.54817053 0.72593246 0.02146791 303 | 0.57990460 0.87921074 0.59913886 0.66726893 0.24269154 304 | 0.73344575 0.71826052 0.92313935 0.05212996 0.93771536 305 | 0.69489385 0.57581887 0.48106155 0.06808800 0.33633940 306 | 0.69142320 0.46566781 0.70654143 0.16541368 0.76257631 307 | 0.82777900 0.62958327 0.34757935 0.10891487 0.79912728 308 | 0.01156543 0.23111261 0.58535640 0.87461956 0.21723454 309 | 0.80409615 0.33169686 0.72800785 0.31218099 0.13729737 310 | 0.41637635 0.01234597 0.58313811 0.66746028 0.05105595 311 | 0.14930937 0.56044864 0.76196851 0.98800104 0.37075949 312 | 0.88740864 0.40697115 0.96598278 0.86013661 0.85386784 313 | 0.23986516 0.39027464 0.59593927 0.00161530 0.31768197 314 | 0.65702729 0.66461914 0.62937471 0.92120758 0.87578958 315 | 0.37539860 0.59182615 0.12092214 0.55130437 0.86365117 316 | 0.38725162 0.28757657 0.42803199 0.39014405 0.50253853 317 | 0.85306128 0.92018995 0.71421618 0.54236780 0.96221157 318 | 0.22956898 0.96519876 0.06694102 0.11915854 0.01354308 319 | 0.24720070 0.71671739 0.00604305 0.65012352 0.71151390 320 | 0.46616159 0.99228224 0.20684576 0.62941006 0.84535326 321 | 0.30678993 0.55264568 0.50094784 0.39409122 0.15479416 322 | 0.36536318 0.51925656 0.65567178 0.67255519 0.55089659 323 | 0.42194295 0.27172413 0.79540954 0.71594806 0.88372598 324 | 0.29179452 0.66411306 0.57064687 0.42494633 0.73389255 325 | 0.12097313 0.53338622 0.38493233 0.79348021 0.01851341 326 | 0.58594454 0.88396240 0.04410730 0.67419924 0.62770011 327 | 0.64644200 0.40335135 0.17952644 0.55564678 0.56643922 328 | 0.37715015 0.87092180 0.56726159 0.34011210 0.13661819 329 | 0.11474177 0.93930097 0.48549077 0.28484289 0.13374371 330 | 0.40966056 0.73662873 0.37355323 0.65216092 0.27372469 331 | 0.56032082 0.14882684 0.95462890 0.17090266 0.92374766 332 | 0.98368259 0.68448367 0.02872548 0.68598279 0.04601084 333 | 0.17170501 0.08906644 0.23730372 0.02929037 0.38566261 334 | 0.68957569 0.53021050 0.44200157 0.32085701 0.72520053 335 | 0.17454174 0.19676599 0.88243877 0.87030228 0.15124486 336 | 0.78670160 0.51731632 0.56674531 0.20910664 0.84962640 337 | 0.05220467 0.91783159 0.19138968 0.68126378 0.79574471 338 | 0.14910848 0.28030331 0.98067264 0.31263980 0.67448964 339 | 0.69266650 0.40033551 0.22789781 0.78317066 0.55815261 340 | 0.11247054 0.47337901 0.46310033 0.53192452 0.56164078 341 | 0.41750378 0.43880622 0.69739327 0.11092778 0.18333765 342 | 0.67222441 0.12789170 0.88316806 0.37891271 0.14935268 343 | 0.64522185 0.93902079 0.62481092 0.21794927 0.71535266 344 | 0.62169579 0.65147153 0.01411645 0.96413465 0.01021578 345 | 0.50605180 0.51595053 0.03308040 0.01497870 0.07809658 346 | 0.35743383 0.58079701 0.11785557 0.89568677 0.38793964 347 | 0.37117709 0.13994133 0.11032813 0.99998594 0.06695042 348 | 0.79774786 0.11093584 0.23879095 0.85918615 0.16109636 349 | 0.63479696 0.75023359 0.29061187 0.53764772 0.30652318 350 | 0.51387302 0.81620973 0.82433610 0.18302488 0.79048957 351 | 0.07598187 0.27887732 0.37061042 0.36441016 0.93736882 352 | 0.77480946 0.02269132 0.40309874 0.16427650 0.13969296 353 | 0.57605029 0.00242426 0.56626691 0.84390990 0.87455806 354 | 0.12321023 0.87561663 0.60431578 0.35880839 0.50426282 355 | 0.50697689 0.06631164 0.14976092 0.89356018 0.91473662 356 | 0.04235237 0.50073724 0.75969690 0.91743994 0.79352335 357 | 0.58078351 0.91819984 0.53520520 0.18267367 0.05608828 358 | 0.68315721 0.27264599 0.41245634 0.69706222 0.69666203 359 | 0.08967342 0.64081905 0.22576796 0.69315628 0.53981640 360 | 0.76059129 0.56712344 0.94318621 0.44081094 0.31699284 361 | 0.29477911 0.80069824 0.28366921 0.96718081 0.85345644 362 | 0.11681215 0.47600710 0.33448255 0.31217271 0.35469241 363 | 0.59511650 0.49583692 0.48922303 0.20215259 0.60159380 364 | 0.17882055 0.77601258 0.71020391 0.41833503 0.71522856 365 | 0.87534517 0.43703394 0.43056077 0.64828071 0.43069441 366 | 0.39356849 0.32063367 0.92788963 0.16878266 0.56762591 367 | 0.56042446 0.84958464 0.79408949 0.08220340 0.13922856 368 | 0.82529019 0.27134959 0.00278080 0.66192389 0.01782933 369 | 0.95404763 0.50787645 0.85320521 0.83690362 0.83771227 370 | 0.46268665 0.31716742 0.01716647 0.68264674 0.01789888 371 | 0.30446846 0.14942271 0.26982182 0.74933947 0.50394161 372 | 0.78444542 0.40009256 0.40333422 0.16627342 0.01898760 373 | 0.04221829 0.77960213 0.66230976 0.56015996 0.49535426 374 | 0.38536259 0.40406773 0.99930568 0.00857945 0.16158390 375 | 0.64805163 0.20237524 0.59106326 0.76968277 0.96887042 376 | 0.29264851 0.97373775 0.16767633 0.33014482 0.27426548 377 | 0.10947014 0.75920652 0.37757457 0.13125207 0.00826451 378 | 0.96684342 0.69362226 0.22763554 0.20717541 0.42112268 379 | 0.22803038 0.33481806 0.14968742 0.71598558 0.55126711 380 | 0.64518015 0.65170197 0.89103003 0.72728361 0.24485454 381 | 0.09410780 0.79818029 0.54212409 0.17790462 0.64442619 382 | 0.62193511 0.51193256 0.02848781 0.05719604 0.45795152 383 | 0.03219332 0.28310254 0.85746127 0.64890240 0.20658356 384 | 0.50946422 0.80432490 0.08354468 0.09222723 0.67455943 385 | 0.44638771 0.76366629 0.99677267 0.89311242 0.11627279 386 | 0.09181302 0.44767077 0.16448724 0.26005539 0.28670391 387 | 0.52465703 0.43598116 0.41869096 0.98043420 0.01497272 388 | 0.51791571 0.61825308 0.85503436 0.63025655 0.02719292 389 | 0.09865668 0.30321729 0.56998039 0.14946350 0.64823918 390 | 0.19931639 0.14623555 0.54169913 0.68944135 0.73551005 391 | 0.46743658 0.04109096 0.26625801 0.09537298 0.98207890 392 | 0.58109721 0.70793680 0.84379365 0.42774726 0.12653597 393 | 0.08566633 0.53366781 0.33960092 0.11036831 0.84464510 394 | 0.16493476 0.92493443 0.87640673 0.52727644 0.57181349 395 | 0.65071340 0.00978637 0.31700693 0.69148222 0.85063311 396 | 0.06781819 0.30794534 0.65541667 0.16400484 0.06886223 397 | 0.96227205 0.09633060 0.34513153 0.31013900 0.78165882 398 | 0.39583699 0.86327936 0.69269199 0.11016575 0.67358419 399 | 0.81775427 0.50052824 0.30068582 0.16606837 0.62243724 400 | 0.47863741 0.68796498 0.31526949 0.41180883 0.23022147 401 | 0.82342139 0.83003381 0.53571829 0.41081533 0.48600142 402 | -------------------------------------------------------------------------------- /mt19937/c/mt19937-64test.c: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937-64 (2014/2/23 version). 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | This is a 64-bit version of Mersenne Twister pseudorandom number 6 | generator. 7 | 8 | Before using, initialize the state by using init_genrand64(seed) 9 | or init_by_array64(init_key, key_length). 10 | 11 | Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions 16 | are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | 3. The names of its contributors may not be used to endorse or promote 26 | products derived from this software without specific prior written 27 | permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | 41 | References: 42 | T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' 43 | ACM Transactions on Modeling and 44 | Computer Simulation 10. (2000) 348--357. 45 | M. Matsumoto and T. Nishimura, 46 | ``Mersenne Twister: a 623-dimensionally equidistributed 47 | uniform pseudorandom number generator'' 48 | ACM Transactions on Modeling and 49 | Computer Simulation 8. (Jan. 1998) 3--30. 50 | 51 | Any feedback is very welcome. 52 | http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) 54 | */ 55 | 56 | #include 57 | #include "mt19937-64.h" 58 | 59 | int main(void) 60 | { 61 | int i; 62 | uint64_t init[4]={UINT64_C(0x12345), UINT64_C(0x23456), UINT64_C(0x34567), UINT64_C(0x45678)}, length=4; 63 | mt19937* mt = mt19937_new(); 64 | mt19937_seed_by_array(mt, init, length); 65 | for (i=0; i<1000; i++) { 66 | printf("%20llu ", mt19937_uint64(mt)); 67 | if (i%5==4) printf("\n"); 68 | } 69 | printf("\n"); 70 | for (i=0; i<1000; i++) { 71 | printf("%10.8f ", mt19937_real2(mt)); 72 | if (i%5==4) printf("\n"); 73 | } 74 | mt19937_free(mt); 75 | return 0; 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /mt19937/csharp/mt19937.cs: -------------------------------------------------------------------------------- 1 | namespace Funny.Crypto 2 | { 3 | /// 4 | /// This code was posted by arithma http://www.lebgeeks.com/forums/viewtopic.php?pid=60482#p60482 5 | /// 6 | public class MT19937 7 | { 8 | /* Period parameters */ 9 | private const int N = 312; 10 | private const int M = 156; 11 | private const ulong MATRIX_A = 0xB5026F5AA96619E9; /* constant vector a */ 12 | private const ulong UPPER_MASK = 0xFFFFFFFF80000000; /* most significant w-r bits */ 13 | private const ulong LOWER_MASK = 0x7FFFFFFF; /* least significant r bits */ 14 | 15 | /* Tempering parameters */ 16 | private const ulong TEMPERING_MASK_B = 0x9d2c5680; 17 | private const ulong TEMPERING_MASK_C = 0xefc60000; 18 | 19 | private static ulong TEMPERING_SHIFT_U(ulong y) { return (y >> 29); } 20 | private static ulong TEMPERING_SHIFT_S(ulong y) { return (y << 17); } 21 | private static ulong TEMPERING_SHIFT_T(ulong y) { return (y << 37); } 22 | private static ulong TEMPERING_SHIFT_L(ulong y) { return (y >> 43); } 23 | 24 | //static unsigned long mt[N]; /* the array for the state vector */ 25 | private ulong[] mt = new ulong[N]; 26 | 27 | // static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 28 | private uint mti = N + 1; /* mti==N+1 means mt[N] is not initialized */ 29 | 30 | /* initializing the array with a NONZERO seed */ 31 | public void Seed(ulong seed) 32 | { 33 | /* setting initial seeds to mt[N] using */ 34 | /* the generator Line 25 of Table 1 in */ 35 | /* [KNUTH 1981, The Art of Computer Programming */ 36 | /* Vol. 2 (2nd Ed.), pp102] */ 37 | 38 | mt[0] = seed; 39 | for (mti = 1; mti < N; mti++) 40 | { 41 | mt[mti] = (6364136223846793005 * (mt[mti - 1] ^ (mt[mti - 1] >> 62)) + mti); 42 | } 43 | } 44 | 45 | /* initialize by an array with array-length */ 46 | /* init_key is the array for initializing keys */ 47 | /* key_length is its length */ 48 | public void Seed(ulong[] init_key) 49 | { 50 | ulong i, j, k; 51 | ulong key_length = (ulong)init_key.Length; 52 | Seed(19650218ULL); 53 | i=1; j=0; 54 | k = (N>key_length ? N : key_length); 55 | for (; k>0; k--) { 56 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 3935559000370003845ULL)) + init_key[j] + j; /* non linear */ 57 | i++; j++; 58 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 59 | if (j>=key_length) j=0; 60 | } 61 | for (k=N-1; k>0; k--) { 62 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 2862933555777941757ULL)) - i; /* non linear */ 63 | i++; 64 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 65 | } 66 | 67 | mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */ 68 | } 69 | 70 | private static ulong[/* 2 */] mag01 = { 0x0, MATRIX_A }; 71 | /* generating reals */ 72 | /* unsigned long */ 73 | /* for integer generation */ 74 | public ulong UInt64() 75 | { 76 | ulong y; 77 | 78 | /* mag01[x] = x * MATRIX_A for x=0,1 */ 79 | if (mti >= N) /* generate N words at one time */ 80 | { 81 | short kk; 82 | 83 | if (mti == N + 1) /* if sgenrand() has not been called, */ 84 | { 85 | Seed(5489); /* a default initial seed is used */ 86 | } 87 | 88 | for (kk = 0; kk < N - M; kk++) 89 | { 90 | y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 91 | mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1]; 92 | } 93 | 94 | for (; kk < N - 1; kk++) 95 | { 96 | y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 97 | mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1]; 98 | } 99 | 100 | y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK); 101 | mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1]; 102 | 103 | mti = 0; 104 | } 105 | 106 | y = mt[mti++]; 107 | y ^= (y >> 29) & 0x5555555555555555; 108 | y ^= (y << 17) & 0x71D67FFFEDA60000; 109 | y ^= (y << 37) & 0xFFF7EEE000000000; 110 | y ^= (y >> 43); 111 | 112 | return y; 113 | } 114 | 115 | /* generates a random number on [0, 2^63-1]-interval */ 116 | public long Int63() 117 | { 118 | return (long)(this.UInt64() >> 1); 119 | } 120 | 121 | /* generates a random number on [0,1]-real-interval */ 122 | public double Real1() 123 | { 124 | return (this.UInt64() >> 11) * (1.0/9007199254740991.0); 125 | } 126 | 127 | /* generates a random number on [0,1)-real-interval */ 128 | public double Real2() 129 | { 130 | return (double)(this.UInt64() >> 11) * (1.0/9007199254740992.0); 131 | } 132 | 133 | /* generates a random number on (0,1)-real-interval */ 134 | public double Real3() 135 | { 136 | return ((double)(this.UInt64() >> 12) + 0.5) * (1.0/4503599627370496.0); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /mt19937/csharp/mt19937_test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Funny.Crypto; 3 | 4 | class MainClass 5 | { 6 | public static void Main(string[] args) { 7 | var mt = new MT19937(); 8 | mt.Seed(new ulong[]{0x12345UL, 0x23456UL, 0x34567UL, 0x45678UL}); 9 | 10 | var i = 0; 11 | foreach (ulong want in expectedInt) { 12 | var have = mt.UInt64(); 13 | if (have != want) { 14 | Console.WriteLine("wrong output {0}: {1} != {2}", i, have, want); 15 | return; 16 | } 17 | i ++; 18 | } 19 | 20 | i = 0; 21 | foreach (string want in expectedReal) { 22 | var have = mt.Real2().ToString("0.00000000"); 23 | if (have != want) { 24 | Console.WriteLine("wrong output {0}: {1} != {2}", i, have, want); 25 | return; 26 | } 27 | i ++; 28 | } 29 | 30 | Console.WriteLine("done"); 31 | } 32 | 33 | // This is the output of the mt19937ar.c program from 34 | // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html 35 | static ulong[] expectedInt = new ulong[]{ 36 | 7266447313870364031, 4946485549665804864, 16945909448695747420, 37 | 16394063075524226720, 4873882236456199058, 14877448043947020171, 38 | 6740343660852211943, 13857871200353263164, 5249110015610582907, 39 | 10205081126064480383, 1235879089597390050, 17320312680810499042, 40 | 16489141110565194782, 8942268601720066061, 13520575722002588570, 41 | 14226945236717732373, 9383926873555417063, 15690281668532552105, 42 | 11510704754157191257, 15864264574919463609, 6489677788245343319, 43 | 5112602299894754389, 10828930062652518694, 15942305434158995996, 44 | 15445717675088218264, 4764500002345775851, 14673753115101942098, 45 | 236502320419669032, 13670483975188204088, 14931360615268175698, 46 | 8904234204977263924, 12836915408046564963, 12120302420213647524, 47 | 15755110976537356441, 5405758943702519480, 10951858968426898805, 48 | 17251681303478610375, 4144140664012008120, 18286145806977825275, 49 | 13075804672185204371, 10831805955733617705, 6172975950399619139, 50 | 12837097014497293886, 12903857913610213846, 560691676108914154, 51 | 1074659097419704618, 14266121283820281686, 11696403736022963346, 52 | 13383246710985227247, 7132746073714321322, 10608108217231874211, 53 | 9027884570906061560, 12893913769120703138, 15675160838921962454, 54 | 2511068401785704737, 14483183001716371453, 3774730664208216065, 55 | 5083371700846102796, 9583498264570933637, 17119870085051257224, 56 | 5217910858257235075, 10612176809475689857, 1924700483125896976, 57 | 7171619684536160599, 10949279256701751503, 15596196964072664893, 58 | 14097948002655599357, 615821766635933047, 5636498760852923045, 59 | 17618792803942051220, 580805356741162327, 425267967796817241, 60 | 8381470634608387938, 13212228678420887626, 16993060308636741960, 61 | 957923366004347591, 6210242862396777185, 1012818702180800310, 62 | 15299383925974515757, 17501832009465945633, 17453794942891241229, 63 | 15807805462076484491, 8407189590930420827, 974125122787311712, 64 | 1861591264068118966, 997568339582634050, 18046771844467391493, 65 | 17981867688435687790, 3809841506498447207, 9460108917638135678, 66 | 16172980638639374310, 958022432077424298, 4393365126459778813, 67 | 13408683141069553686, 13900005529547645957, 15773550354402817866, 68 | 16475327524349230602, 6260298154874769264, 12224576659776460914, 69 | 6405294864092763507, 7585484664713203306, 5187641382818981381, 70 | 12435998400285353380, 13554353441017344755, 646091557254529188, 71 | 11393747116974949255, 16797249248413342857, 15713519023537495495, 72 | 12823504709579858843, 4738086532119935073, 4429068783387643752, 73 | 585582692562183870, 1048280754023674130, 6788940719869959076, 74 | 11670856244972073775, 2488756775360218862, 2061695363573180185, 75 | 6884655301895085032, 3566345954323888697, 12784319933059041817, 76 | 4772468691551857254, 6864898938209826895, 7198730565322227090, 77 | 2452224231472687253, 13424792606032445807, 10827695224855383989, 78 | 11016608897122070904, 14683280565151378358, 7077866519618824360, 79 | 17487079941198422333, 3956319990205097495, 5804870313319323478, 80 | 8017203611194497730, 3310931575584983808, 5009341981771541845, 81 | 6930001938490791874, 14415278059151389495, 11001114762641844083, 82 | 6715939435439735925, 411419160297131328, 4522402260441335284, 83 | 3381955501804126859, 15935778656111987797, 4345051260540166684, 84 | 13978444093099579683, 9219789505504949817, 9245142924137529075, 85 | 11628184459157386459, 7242398879359936370, 8511401943157540109, 86 | 11948130810477009827, 6865450671488705049, 13965005347172621081, 87 | 15956599226522058336, 7737868921014130584, 2107342503741411693, 88 | 15818996300425101108, 16399939197527488760, 13971145494081508107, 89 | 3910681448359868691, 4249175367970221090, 9735751321242454020, 90 | 12418107929362160460, 241792245481991138, 5806488997649497146, 91 | 10724207982663648949, 1121862814449214435, 1326996977123564236, 92 | 4902706567834759475, 12782714623891689967, 7306216312942796257, 93 | 15681656478863766664, 957364844878149318, 5651946387216554503, 94 | 8197027112357634782, 6302075516351125977, 13454588464089597862, 95 | 15638309200463515550, 10116604639722073476, 12052913535387714920, 96 | 2889379661594013754, 15383926144832314187, 7841953313015471731, 97 | 17310575136995821873, 9820021961316981626, 15319619724109527290, 98 | 15349724127275899898, 10511508162402504492, 6289553862380300393, 99 | 15046218882019267110, 11772020174577005930, 3537640779967351792, 100 | 6801855569284252424, 17687268231192623388, 12968358613633237218, 101 | 1429775571144180123, 10427377732172208413, 12155566091986788996, 102 | 16465954421598296115, 12710429690464359999, 9547226351541565595, 103 | 12156624891403410342, 2985938688676214686, 18066917785985010959, 104 | 5975570403614438776, 11541343163022500560, 11115388652389704592, 105 | 9499328389494710074, 9247163036769651820, 3688303938005101774, 106 | 2210483654336887556, 15458161910089693228, 6558785204455557683, 107 | 1288373156735958118, 18433986059948829624, 3435082195390932486, 108 | 16822351800343061990, 3120532877336962310, 16681785111062885568, 109 | 7835551710041302304, 2612798015018627203, 15083279177152657491, 110 | 6591467229462292195, 10592706450534565444, 7438147750787157163, 111 | 323186165595851698, 7444710627467609883, 8473714411329896576, 112 | 2782675857700189492, 3383567662400128329, 3200233909833521327, 113 | 12897601280285604448, 3612068790453735040, 8324209243736219497, 114 | 15789570356497723463, 1083312926512215996, 4797349136059339390, 115 | 5556729349871544986, 18266943104929747076, 1620389818516182276, 116 | 172225355691600141, 3034352936522087096, 1266779576738385285, 117 | 3906668377244742888, 6961783143042492788, 17159706887321247572, 118 | 4676208075243319061, 10315634697142985816, 13435140047933251189, 119 | 716076639492622016, 13847954035438697558, 7195811275139178570, 120 | 10815312636510328870, 6214164734784158515, 16412194511839921544, 121 | 3862249798930641332, 1005482699535576005, 4644542796609371301, 122 | 17600091057367987283, 4209958422564632034, 5419285945389823940, 123 | 11453701547564354601, 9951588026679380114, 7425168333159839689, 124 | 8436306210125134906, 11216615872596820107, 3681345096403933680, 125 | 5770016989916553752, 11102855936150871733, 11187980892339693935, 126 | 396336430216428875, 6384853777489155236, 7551613839184151117, 127 | 16527062023276943109, 13429850429024956898, 9901753960477271766, 128 | 9731501992702612259, 5217575797614661659, 10311708346636548706, 129 | 15111747519735330483, 4353415295139137513, 1845293119018433391, 130 | 11952006873430493561, 3531972641585683893, 16852246477648409827, 131 | 15956854822143321380, 12314609993579474774, 16763911684844598963, 132 | 16392145690385382634, 1545507136970403756, 17771199061862790062, 133 | 12121348462972638971, 12613068545148305776, 954203144844315208, 134 | 1257976447679270605, 3664184785462160180, 2747964788443845091, 135 | 15895917007470512307, 15552935765724302120, 16366915862261682626, 136 | 8385468783684865323, 10745343827145102946, 2485742734157099909, 137 | 916246281077683950, 15214206653637466707, 12895483149474345798, 138 | 1079510114301747843, 10718876134480663664, 1259990987526807294, 139 | 8326303777037206221, 14104661172014248293, 15531278677382192198, 140 | 3874303698666230242, 3611366553819264523, 1358753803061653874, 141 | 1552102816982246938, 14492630642488100979, 15001394966632908727, 142 | 2273140352787320862, 17843678642369606172, 2903980458593894032, 143 | 16971437123015263604, 12969653681729206264, 3593636458822318001, 144 | 9719758956915223015, 7437601263394568346, 3327758049015164431, 145 | 17851524109089292731, 14769614194455139039, 8017093497335662337, 146 | 12026985381690317404, 739616144640253634, 15535375191850690266, 147 | 2418267053891303448, 15314073759564095878, 10333316143274529509, 148 | 16565481511572123421, 16317667579273275294, 13991958187675987741, 149 | 3753596784796798785, 9078249094693663275, 8459506356724650587, 150 | 12579909555010529099, 7827737296967050903, 5489801927693999341, 151 | 10995988997350541459, 14721747867313883304, 7915884580303296560, 152 | 4105766302083365910, 12455549072515054554, 13602111324515032467, 153 | 5205971628932290989, 5034622965420036444, 9134927878875794005, 154 | 11319873529597990213, 14815445109496752058, 2266601052460299470, 155 | 5696993487088103383, 6540200741841280242, 6631495948031875490, 156 | 5328340585170897740, 17897267040961463930, 9030000260502624168, 157 | 14285709137129830926, 12854071997824681544, 15408328651008978682, 158 | 1063314403033437073, 13765209628446252802, 242013711116865605, 159 | 4772374239432528212, 2515855479965038648, 5872624715703151235, 160 | 14237704570091006662, 678604024776645862, 12329607334079533339, 161 | 17570877682732917020, 2695443415284373666, 4312672841405514468, 162 | 6454343485137106900, 8425658828390111343, 16335501385875554899, 163 | 5551095603809016713, 11781094401885925035, 9395557946368382509, 164 | 9765123360948816956, 18107191819981188154, 16049267500594757404, 165 | 16349966108299794199, 1040405303135858246, 2366386386131378192, 166 | 223761048139910454, 15375217587047847934, 15231693398695187454, 167 | 12916726640254571028, 8878036960829635584, 1626201782473074365, 168 | 5758998126998248293, 18077917959300292758, 10585588923088536745, 169 | 15072345664541731497, 3559348759319842667, 12744591691872202375, 170 | 2388494115860283059, 6414691845696331748, 3069528498807764495, 171 | 8737958486926519702, 18059264986425101074, 3139684427605102737, 172 | 12378931902986734693, 410666675039477949, 12139894855769838924, 173 | 5780722552400398675, 7039346665375142557, 3020733445712569008, 174 | 2612305843503943561, 13651771214166527665, 16478681918975800939, 175 | 566088527565499576, 4715785502295754870, 6957318344287196220, 176 | 11645756868405128885, 13139951104358618000, 17650948583490040612, 177 | 18168787973649736637, 5486282999836125542, 6122201977153895166, 178 | 17324241605502052782, 10063523107521105867, 17537430712468011382, 179 | 10828407533637104262, 10294139354198325113, 12557151830240236401, 180 | 16673044307512640231, 10918020421896090419, 11077531235278014145, 181 | 5499571814940871256, 2334252435740638702, 18177461912527387031, 182 | 2000007376901262542, 7968425560071444214, 1472650787501520648, 183 | 3115849849651526279, 7980970700139577536, 12153253535907642097, 184 | 8109716914843248719, 3154976533165008908, 5553369513523832559, 185 | 10345792701798576501, 3677445364544507875, 10637177623943913351, 186 | 7380255087060498096, 14479400372337014801, 15381362583330700960, 187 | 204531043189704802, 13699106540959723942, 3817903465872254783, 188 | 10972364467110284934, 2701394334530963810, 2931625600749229147, 189 | 16428252083632828910, 11873166501966812913, 5566810080537233762, 190 | 7840617383807795056, 10699413880206684652, 18259119259617231436, 191 | 10332714341486317526, 10137911902863059694, 669146221352346842, 192 | 8373571610024623455, 10620002450820868661, 12220730820779815970, 193 | 5902974968095412898, 7931010481705150841, 16413777368097063650, 194 | 11273457888324769727, 13719113891065284171, 8327795098009702553, 195 | 10333342364827584837, 6202832891413866653, 9137034567886143162, 196 | 14514450826524340059, 473610156015331016, 813689571029117640, 197 | 13776316799690285717, 10429708855338427756, 8995290140880620858, 198 | 2320123852041754384, 8082864073645003641, 6961777411740398590, 199 | 10008644283003991179, 3239064015890722333, 16762634970725218787, 200 | 16467281536733948427, 10563290046315192938, 5108560603794851559, 201 | 15121667220761532906, 14155440077372845941, 10050536352394623377, 202 | 15474881667376037792, 3448088038819200619, 3692020001240358871, 203 | 6444847992258394902, 8687650838094264665, 3028124591188972359, 204 | 16945232313401161629, 15547830510283682816, 3982930188609442149, 205 | 14270781928849894661, 13768475593433447867, 13815150225221307677, 206 | 8502397232429564693, 718377350715476994, 7459266877697905475, 207 | 8353375565171101521, 7807281661994435472, 16924127046922196149, 208 | 10157812396471387805, 2519858716882670232, 7384148884750265792, 209 | 8077153156180046901, 3499231286164597752, 2700106282881469611, 210 | 14679824700835879737, 14188324938219126828, 3016120398601032793, 211 | 10858152824243889420, 9412371965669250534, 4857522662584941069, 212 | 984331743838900386, 4094160040294753142, 2368635764350388458, 213 | 15101240511397838657, 15584415763303953578, 7831857200208015446, 214 | 1952643641639729063, 4184323302594028609, 16795120381104846695, 215 | 3541559381538365280, 15408472870896842474, 5628362450757896366, 216 | 16277348886873708846, 12437047172652330846, 10172715019035948149, 217 | 1999700669649752791, 6217957085626135027, 11220551167830336823, 218 | 16478747645632411810, 5437280487207382147, 11382378739613087836, 219 | 15866932785489521505, 5502694314775516684, 16440179278067648435, 220 | 15510104554374162846, 15722061259110909195, 10760687291786964354, 221 | 10736868329920212671, 4166148127664495614, 14303518358120527892, 222 | 9122250801678898571, 10028508179936801946, 216630713752669403, 223 | 10655207865433859491, 4041437116174699233, 6280982262534375348, 224 | 297501356638818866, 13976146806363377485, 13752396481560145603, 225 | 11472199956603637419, 16393728429143900496, 14752844047515986640, 226 | 1524477318846038424, 6596889774254235440, 1591982099532234960, 227 | 8065146456116391065, 3964696017750868345, 17040425970526664920, 228 | 11511165586176539991, 3443401252003315103, 16314977947073778249, 229 | 16860120454903458341, 5370503221561340846, 15362920279125264094, 230 | 2822458124714999779, 14575378304387898337, 9689406052675046032, 231 | 2872149351415175149, 13019620945255883050, 14929026760148695825, 232 | 8503417349692327218, 9677798905341573754, 828949921821462483, 233 | 16110482368362750196, 15794218816553655671, 14942910774764855088, 234 | 12026350906243760195, 13610867176871462505, 18324536557697872582, 235 | 2658962269666727629, 327225403251576027, 9207535177029277544, 236 | 8744129291351887858, 6129603385168921503, 18385497655031085907, 237 | 13024478718952333892, 14547683159720717167, 5932119629366981711, 238 | 325385464632594563, 3559879386019806291, 6629264948665231298, 239 | 14358245326238118181, 15662449672706340765, 13975503159145803297, 240 | 3609534220891499022, 4224273587485638227, 9274084767162416370, 241 | 13156843921244091998, 18284750575626858789, 14664767920489118779, 242 | 11292057742031803221, 13919998707305829132, 14473305049457001422, 243 | 9696877879685767807, 1406758246007973837, 2429517644459056881, 244 | 14361215588101587430, 11386164476149757528, 10474116023593331839, 245 | 2921165656527786564, 15604610369733358953, 12955027028676000544, 246 | 10314281035410779907, 3167047178514709947, 1088721329408346700, 247 | 17930425515478182741, 7466411836095405617, 15534027454610690575, 248 | 10879629128927506091, 11502219301371200635, 13915106894453889418, 249 | 4226784327815861027, 12335222183627106346, 3648499746356007767, 250 | 18441388887898023393, 18117929843327093625, 4237736098094830438, 251 | 14229123019768296655, 3930112058127932690, 12663879236019645778, 252 | 9281161952002617309, 4978473890680876319, 845759387067546611, 253 | 1386164484606776333, 8008554770639925512, 11159581016793288971, 254 | 18065390393740782906, 17647985458967631018, 9092379465737744314, 255 | 2914678236848656327, 4376066698447630270, 16057186499919087528, 256 | 3031333261848790078, 2926746602873431597, 7931945763526885287, 257 | 147649915388326849, 15801792398814946230, 5265900391686545347, 258 | 16173686275871890830, 7562781050481886043, 5853506575839330404, 259 | 14957980734704564792, 10944286556353523404, 1783009880614150597, 260 | 9529762028588888983, 822992871011696119, 2130074274744257510, 261 | 8000279549284809219, 3514744284158856431, 128770032569293263, 262 | 3737367602618100572, 16364836605077998543, 783266423471782696, 263 | 4569418252658970391, 11093950688157406886, 14888808512267628166, 264 | 4217786261273670948, 17047486076688645713, 14133826721458860485, 265 | 17539744882220127106, 12394675039129853905, 5757634999463277090, 266 | 9621947619435861331, 1182210208559436772, 14603391040490913939, 267 | 17481976703660945893, 14063388816234683976, 2046622692581829572, 268 | 8294969799792017441, 5293778434844788058, 17976364049306763808, 269 | 399482430848083948, 16495545010129798933, 15241340958282367519, 270 | 989828753826900814, 17616558773874893537, 2471817920909589004, 271 | 11764082277667899978, 9618755269550400950, 1240014743757147125, 272 | 1887649378641563002, 1842982574728131416, 13243531042427194002, 273 | 7688268125537013927, 3080422097287486736, 2562894809975407783, 274 | 12428984115620094788, 1355581933694478148, 9895969242586224966, 275 | 8628445623963160889, 4298916726468199239, 12773165416305557280, 276 | 5240726258301567487, 4975412836403427561, 1842172398579595303, 277 | 7812151462958058676, 17974510987263071769, 14980707022065991200, 278 | 18294903201142729875, 12911672684850242753, 8979482998667235743, 279 | 16808468362384462073, 5981317232108359798, 12373702800369335100, 280 | 16119707581920094765, 2782738549717633602, 15454155188515389391, 281 | 16495638000603654629, 16348757069342790497, 7769562861984504567, 282 | 17504300515449231559, 5557710032938318996, 11846125204788401203, 283 | 13957316349928882624, 2738350683717432043, 15738068448047700954, 284 | 6224714837294524999, 6081930777706411111, 11366312928059597928, 285 | 4355315799925031482, 12393324728734964015, 15277140291994338591, 286 | 1406052433297386355, 15859448364509213398, 1672805458341158435, 287 | 2926095111610982994, 11056431822276774455, 12083767323511977430, 288 | 3296968762229741153, 12312076899982286460, 17769284994682227273, 289 | 15349428916826953443, 1056147296359223910, 18305757538706977431, 290 | 6214378374180465222, 14279648441175008454, 17791306410319136644, 291 | 956593013486324072, 2921235772936241950, 10002890515925652606, 292 | 10399654693663712506, 6446247931049971441, 6380465770144534958, 293 | 11439178472613251620, 10131486500045494660, 3692642123868351947, 294 | 10972816599561388940, 4931112976348785580, 8213967169213816566, 295 | 15336469859637867841, 15026830342847689383, 7524668622380765825, 296 | 17309937346758783807, 372780684412666438, 5642417144539399955, 297 | 18303842993081194577, 11085303253831702827, 15658163165983586950, 298 | 8517521928922081563, 16091186344159989860, 17614656488010863910, 299 | 4736067146481515156, 13449945221374241354, 17755469346196579408, 300 | 13300502638545717375, 6611828134763118043, 14177591906740276597, 301 | 9340430243077460347, 7499765399826404087, 3409518087967832469, 302 | 9013253864026602045, 4444307427984430192, 3729283608700519712, 303 | 13642048880719588383, 16486557958022946240, 2996465014991157904, 304 | 10020049344596426576, 12302485648009883778, 8492591321344423126, 305 | 17407986443716172520, 10530482934957373052, 15740662350540828750, 306 | 1790629986901049436, 6305948377669917188, 15092985352503125323, 307 | 928505047232899787, 14404651977039851607, 7564177565277805597, 308 | 3411236815351677870, 7752718145953236134, 12315979971311483798, 309 | 12477729506691004724, 14654956300924793305, 6689803038918974388, 310 | 1540738812233000153, 13508351811701989957, 15864432023192136053, 311 | 7990997967273843917, 7424300239290765161, 39585249496300263, 312 | 3877436595063283319, 10710642254398044448, 4653804418844456375, 313 | 1232267496410380283, 3690525514009038824, 15459770765077428485, 314 | 13240346522153894145, 5674964360688390624, 16973644653010587289, 315 | 15924280764204855206, 15196708627253442662, 17596174821341373274, 316 | 16196745023027393691, 6980050627399795351, 17582264380857746637, 317 | 18170372407506856324, 12108126025631005514, 15687749089493373169, 318 | 5814107289258228434, 9381977959648494876, 15895601183088112734, 319 | 16267869075651604263, 15228381979765852785, 11949618678312581999, 320 | 4545324791131029438, 582725409406225185, 15282520250746126790, 321 | 14758446535973412711, 7605613563088071833, 1111140641057375915, 322 | 5364843095234852245, 218335432181198977, 4891472444796201742, 323 | 4564628942836375772, 15500501278323817088, 4913946328556108657, 324 | 2684786251736694229, 12090498456116310122, 5310885782157038567, 325 | 5032788439854011923, 12627401038822728242, 11869662610126430929, 326 | 17650156853043540226, 12126672500118808436, 10437658933435653256, 327 | 13133995470637873311, 4601324715591152820, 1874350460376708372, 328 | 5808688626286061164, 13777088437302430376, 5018451954762213522, 329 | 2588296738534474754, 5503414509154170711, 5230497186769951796, 330 | 13261090710400573914, 8515217303152165705, 11074538219737365303, 331 | 15481562385740613213, 12705484409881007350, 14221931471178549498, 332 | 12905633420087112297, 17337759164357146506, 14081997515778175224, 333 | 17384320185513122939, 7131793076779216692, 17483217190312403109, 334 | 900692047897995877, 14723287313048560400, 6132094372965340305, 335 | 7572797575350925726, 12725160700431903514, 380860122911632449, 336 | 1900504978569024571, 8423729759529914138, 7305587201606052334, 337 | 12446871355267313320, 4615812356515386206, 3361817115406652303, 338 | 17690418922000878428, 14632214537567910559, 2709702289926174775, 339 | 3459675155951086144, 7788364399926538150, 16043992474431955950, 340 | 15830963823784930267, 4216893617835797954, 538159724689093771, 341 | 16029152738918251363, 14444848757576686696, 12941757045272633696, 342 | 10900480525147953314, 12547307449905859302, 16001571796892398181, 343 | 407942194622690676, 13873235372903944444, 18071603799493008777, 344 | 1015646077646778622, 9387605808959554815, 11566702442022019410, 345 | 7061722181092883183, 2629032108249254109, 5271820053177594520, 346 | 12640880742139693547, 10098688629735675775, 5716304472850923064, 347 | 3312674502353063071, 7295926377425759633, 833281439103466115, 348 | 16316743519466861667, 9912050326606348167, 11651133878100804242, 349 | 18026798122431692459, 6157758321723692663, 4856021830695749349, 350 | 7074321707293278978, 10748097797809573561, 2949954440753264783, 351 | 9813922580940661152, 9949237950172138336, 15643982711269455885, 352 | 16078663425810239127, 12508044395364228880, 12920301578340189344, 353 | 15368071871011048915, 1610400750626363239, 11994736084146033126, 354 | 6042574085746186088, 4154587549267685807, 15915752367312946034, 355 | 1191196620621769193, 467437822242538360, 2836463788873877488, 356 | 10476401302029164984, 1716169985450737419, 5327734953288310341, 357 | 3994170067185955262, 884431883768190063, 11019001754831208284, 358 | 14322807384384895215, 161011537360955545, 1466223959660131656, 359 | 5227048585229497539, 12410731857504225031, 2142243279080761103, 360 | 17682826799106851430, 1792612570704179953, 14727410295243056025, 361 | 1459567192481221274, 5669760721687603135, 17507918443756456845, 362 | 10354471145847018200, 10362475129248202288, 13143844410150939443, 363 | 6861184673150072028, 18396524361124732580, 543906666394301875, 364 | 12476817828199026728, 11853496871128122868, 12747674713108891748, 365 | 7986179867749890282, 9158195177777627533, 2217320706811118570, 366 | 8631389005200569973, 5538133061362648855, 3369942850878700758, 367 | 7813559982698427184, 509051590411815948, 10197035660403006684, 368 | 13004818533162292132, 9831652587047067687, 7619315254749630976, 369 | 994412663058993407, 370 | }; 371 | 372 | static string[] expectedReal = new string[]{ 373 | "0.35252031", "0.51052342", "0.79771733", "0.39300273", "0.27216673", 374 | "0.72151068", "0.43144703", "0.38522290", "0.20270676", "0.58227313", 375 | "0.80812143", "0.83767297", "0.92401619", "0.84065425", "0.00852052", 376 | "0.13975395", "0.35250930", "0.71196972", "0.14627395", "0.17775331", 377 | "0.61046382", "0.49623272", "0.23292425", "0.25038837", "0.04380664", 378 | "0.43275994", "0.74540936", "0.33830700", "0.68832616", "0.68744230", 379 | "0.63626548", "0.85932936", "0.37089670", "0.50756304", "0.69925960", 380 | "0.83481025", "0.09053196", "0.09523253", "0.17783108", "0.78027239", 381 | "0.70071054", "0.51879252", "0.83027285", "0.92895011", "0.72144803", 382 | "0.18868644", "0.83655674", "0.20358945", "0.99852143", "0.88340103", 383 | "0.46729949", "0.96993433", "0.00162682", "0.46829774", "0.59080423", 384 | "0.54921999", "0.42516462", "0.54952196", "0.99534722", "0.04473888", 385 | "0.71139235", "0.91881407", "0.33781561", "0.45746234", "0.78292126", 386 | "0.69206723", "0.66175448", "0.07091147", "0.18179208", "0.38168454", 387 | "0.38819527", "0.42452711", "0.22732724", "0.16191307", "0.36842667", 388 | "0.13060083", "0.68833248", "0.60498705", "0.19195304", "0.26628584", 389 | "0.17030858", "0.23892426", "0.38430236", "0.28034283", "0.76069020", 390 | "0.21560653", "0.78101667", "0.90847812", "0.06467974", "0.18487868", 391 | "0.23570471", "0.29475460", "0.65563767", "0.10066446", "0.57272419", 392 | "0.88731391", "0.60650995", "0.96346079", "0.32940100", "0.29977746", 393 | "0.03798193", "0.18026822", "0.22402746", "0.45480119", "0.98114604", 394 | "0.25800668", "0.94362433", "0.17901062", "0.36019313", "0.45933644", 395 | "0.68309457", "0.28175454", "0.00774729", "0.77054527", "0.99723413", 396 | "0.59807532", "0.10294164", "0.32429228", "0.54928986", "0.18410980", 397 | "0.08441555", "0.14230333", "0.58892064", "0.94030475", "0.35378784", 398 | "0.77584320", "0.71222448", "0.83565208", "0.47309248", "0.23810761", 399 | "0.74408520", "0.08891527", "0.09729786", "0.38377368", "0.05092308", 400 | "0.69065638", "0.10449489", "0.45050670", "0.92209534", "0.80083714", 401 | "0.27902692", "0.26897142", "0.50650468", "0.80111472", "0.54590012", 402 | "0.96406097", "0.63779553", "0.81054357", "0.75369248", "0.47473037", 403 | "0.89100315", "0.89395984", "0.09985519", "0.34087631", "0.22293557", 404 | "0.24375510", "0.31764191", "0.04076993", "0.06160830", "0.41333434", 405 | "0.11883030", "0.04548820", "0.01008040", "0.25336184", "0.07325432", 406 | "0.49860151", "0.07148695", "0.89483338", "0.87054457", "0.15116809", 407 | "0.59650469", "0.47487776", "0.43490298", "0.36684681", "0.16470796", 408 | "0.76865078", "0.42920071", "0.20545481", "0.87615922", "0.80332404", 409 | "0.36462506", "0.49571309", "0.51904488", "0.15534589", "0.43719893", 410 | "0.16562157", "0.37290862", "0.91842631", "0.21310523", "0.87849154", 411 | "0.18532269", "0.81713354", "0.52182344", "0.51845619", "0.96261204", 412 | "0.18758718", "0.68897600", "0.61484764", "0.46752993", "0.05865458", 413 | "0.11614359", "0.90386866", "0.45781805", "0.70649579", "0.50917048", 414 | "0.21210656", "0.97818608", "0.00788342", "0.61375222", "0.67366318", 415 | "0.24197878", "0.66177985", "0.10463932", "0.67390799", "0.50025262", 416 | "0.88332650", "0.77966851", "0.13403622", "0.54357114", "0.97664854", 417 | "0.06540961", "0.24013176", "0.67234032", "0.91347883", "0.35486839", 418 | "0.87207865", "0.43036581", "0.23652488", "0.81238450", "0.72058432", 419 | "0.42239916", "0.80265764", "0.03552838", "0.61939480", "0.50972420", 420 | "0.21053832", "0.59952743", "0.36821802", "0.45659617", "0.12529468", 421 | "0.76941623", "0.99878168", "0.08602783", "0.81825937", "0.39350710", 422 | "0.86090923", "0.36090230", "0.75628888", "0.45036982", "0.44602266", 423 | "0.20595631", "0.62241953", "0.36777732", "0.47523727", "0.50248178", 424 | "0.73570362", "0.48237781", "0.45590948", "0.73580783", "0.96403851", 425 | "0.94586342", "0.48819868", "0.48102038", "0.94618182", "0.90279924", 426 | "0.78396650", "0.85182389", "0.92149394", "0.32679198", "0.83554856", 427 | "0.28320609", "0.34598409", "0.82090005", "0.40177958", "0.38888785", 428 | "0.77873931", "0.23297931", "0.75329335", "0.30770340", "0.71417540", 429 | "0.68939065", "0.36577776", "0.50784857", "0.50928090", "0.02552055", 430 | "0.85999075", "0.26692089", "0.01402799", "0.67550392", "0.48305605", 431 | "0.74608351", "0.63408891", "0.58904230", "0.44337996", "0.42174728", 432 | "0.74041679", "0.72719148", "0.19801992", "0.66263633", "0.10381594", 433 | "0.32818760", "0.68369661", "0.56076212", "0.68681921", "0.91616269", 434 | "0.39836106", "0.39685027", "0.97507945", "0.91010563", "0.27447360", 435 | "0.95538357", "0.76758522", "0.60091060", "0.37734461", "0.82948248", 436 | "0.06598078", "0.50147615", "0.08417763", "0.18910044", "0.51661735", 437 | "0.55011011", "0.64888175", "0.82986845", "0.15126656", "0.92649390", 438 | "0.25494941", "0.73275293", "0.94184393", "0.84755226", "0.45921936", 439 | "0.72934054", "0.43722403", "0.34305596", "0.10827860", "0.29026676", 440 | "0.01935431", "0.46668573", "0.83247509", "0.26349603", "0.01938542", 441 | "0.43222250", "0.18109983", "0.29337450", "0.16721917", "0.94751650", 442 | "0.67795254", "0.56666228", "0.20699452", "0.23247262", "0.19138610", 443 | "0.73495506", "0.85893600", "0.83411526", "0.93689655", "0.91804752", 444 | "0.99352333", "0.03207550", "0.28386071", "0.48029543", "0.18736013", 445 | "0.31736452", "0.72542230", "0.57530912", "0.04229918", "0.84798296", 446 | "0.21886935", "0.98655615", "0.52243102", "0.22611020", "0.42975741", 447 | "0.21726739", "0.10912048", "0.96684473", "0.01092456", "0.12461901", 448 | "0.57989070", "0.39848707", "0.06330277", "0.62826828", "0.01159081", 449 | "0.23157320", "0.64690912", "0.44876902", "0.04463930", "0.18933780", 450 | "0.21284518", "0.61363480", "0.67144845", "0.38625586", "0.75719122", 451 | "0.40361050", "0.26708873", "0.54534727", "0.90174015", "0.58654140", 452 | "0.44885346", "0.35505544", "0.65317830", "0.26074572", "0.39472912", 453 | "0.54366914", "0.75020660", "0.76113614", "0.24595582", "0.03941247", 454 | "0.60356153", "0.23615721", "0.01603475", "0.72432457", "0.39837424", 455 | "0.04195329", "0.81561058", "0.34208440", "0.00513953", "0.92826234", 456 | "0.11410393", "0.86692030", "0.25238726", "0.98258626", "0.53353856", 457 | "0.72269001", "0.71850984", "0.66829681", "0.03540769", "0.01676450", 458 | "0.23557835", "0.78758497", "0.85969589", "0.14673207", "0.28013860", 459 | "0.17796942", "0.69924087", "0.44663597", "0.62112513", "0.44079883", 460 | "0.48995231", "0.18411497", "0.18440877", "0.74016388", "0.28845694", 461 | "0.22969080", "0.76851164", "0.15551473", "0.28980810", "0.40906710", 462 | "0.47619039", "0.72611392", "0.55802939", "0.69365597", "0.85736313", 463 | "0.83343150", "0.21324760", "0.45327806", "0.33053855", "0.98198279", 464 | "0.53279389", "0.76877035", "0.20548656", "0.37065042", "0.59026910", 465 | "0.67418036", "0.23585843", "0.98156397", "0.27849804", "0.56198954", 466 | "0.68752287", "0.30073445", "0.69348664", "0.72515585", "0.40629047", 467 | "0.09320027", "0.24334978", "0.91407662", "0.97226538", "0.33904970", 468 | "0.01717092", "0.60155725", "0.03001652", "0.50979706", "0.80531036", 469 | "0.17450719", "0.84984399", "0.00498130", "0.51636405", "0.14080868", 470 | "0.62289701", "0.07853030", "0.70567541", "0.79844050", "0.63766566", 471 | "0.03559031", "0.40994535", "0.08423996", "0.00389626", "0.50608347", 472 | "0.19622681", "0.90537903", "0.75458034", "0.75102094", "0.81491673", 473 | "0.92925931", "0.38074332", "0.54817053", "0.72593246", "0.02146791", 474 | "0.57990460", "0.87921074", "0.59913886", "0.66726893", "0.24269154", 475 | "0.73344575", "0.71826052", "0.92313935", "0.05212996", "0.93771536", 476 | "0.69489385", "0.57581887", "0.48106155", "0.06808800", "0.33633940", 477 | "0.69142320", "0.46566781", "0.70654143", "0.16541368", "0.76257631", 478 | "0.82777900", "0.62958327", "0.34757935", "0.10891487", "0.79912728", 479 | "0.01156543", "0.23111261", "0.58535640", "0.87461956", "0.21723454", 480 | "0.80409615", "0.33169686", "0.72800785", "0.31218099", "0.13729737", 481 | "0.41637635", "0.01234597", "0.58313811", "0.66746028", "0.05105595", 482 | "0.14930937", "0.56044864", "0.76196851", "0.98800104", "0.37075949", 483 | "0.88740864", "0.40697115", "0.96598278", "0.86013661", "0.85386784", 484 | "0.23986516", "0.39027464", "0.59593927", "0.00161530", "0.31768197", 485 | "0.65702729", "0.66461914", "0.62937471", "0.92120758", "0.87578958", 486 | "0.37539860", "0.59182615", "0.12092214", "0.55130437", "0.86365117", 487 | "0.38725162", "0.28757657", "0.42803199", "0.39014405", "0.50253853", 488 | "0.85306128", "0.92018995", "0.71421618", "0.54236780", "0.96221157", 489 | "0.22956898", "0.96519876", "0.06694102", "0.11915854", "0.01354308", 490 | "0.24720070", "0.71671739", "0.00604305", "0.65012352", "0.71151390", 491 | "0.46616159", "0.99228224", "0.20684576", "0.62941006", "0.84535326", 492 | "0.30678993", "0.55264568", "0.50094784", "0.39409122", "0.15479416", 493 | "0.36536318", "0.51925656", "0.65567178", "0.67255519", "0.55089659", 494 | "0.42194295", "0.27172413", "0.79540954", "0.71594806", "0.88372598", 495 | "0.29179452", "0.66411306", "0.57064687", "0.42494633", "0.73389255", 496 | "0.12097313", "0.53338622", "0.38493233", "0.79348021", "0.01851341", 497 | "0.58594454", "0.88396240", "0.04410730", "0.67419924", "0.62770011", 498 | "0.64644200", "0.40335135", "0.17952644", "0.55564678", "0.56643922", 499 | "0.37715015", "0.87092180", "0.56726159", "0.34011210", "0.13661819", 500 | "0.11474177", "0.93930097", "0.48549077", "0.28484289", "0.13374371", 501 | "0.40966056", "0.73662873", "0.37355323", "0.65216092", "0.27372469", 502 | "0.56032082", "0.14882684", "0.95462890", "0.17090266", "0.92374766", 503 | "0.98368259", "0.68448367", "0.02872548", "0.68598279", "0.04601084", 504 | "0.17170501", "0.08906644", "0.23730372", "0.02929037", "0.38566261", 505 | "0.68957569", "0.53021050", "0.44200157", "0.32085701", "0.72520053", 506 | "0.17454174", "0.19676599", "0.88243877", "0.87030228", "0.15124486", 507 | "0.78670160", "0.51731632", "0.56674531", "0.20910664", "0.84962640", 508 | "0.05220467", "0.91783159", "0.19138968", "0.68126378", "0.79574471", 509 | "0.14910848", "0.28030331", "0.98067264", "0.31263980", "0.67448964", 510 | "0.69266650", "0.40033551", "0.22789781", "0.78317066", "0.55815261", 511 | "0.11247054", "0.47337901", "0.46310033", "0.53192452", "0.56164078", 512 | "0.41750378", "0.43880622", "0.69739327", "0.11092778", "0.18333765", 513 | "0.67222441", "0.12789170", "0.88316806", "0.37891271", "0.14935268", 514 | "0.64522185", "0.93902079", "0.62481092", "0.21794927", "0.71535266", 515 | "0.62169579", "0.65147153", "0.01411645", "0.96413465", "0.01021578", 516 | "0.50605180", "0.51595053", "0.03308040", "0.01497870", "0.07809658", 517 | "0.35743383", "0.58079701", "0.11785557", "0.89568677", "0.38793964", 518 | "0.37117709", "0.13994133", "0.11032813", "0.99998594", "0.06695042", 519 | "0.79774786", "0.11093584", "0.23879095", "0.85918615", "0.16109636", 520 | "0.63479696", "0.75023359", "0.29061187", "0.53764772", "0.30652318", 521 | "0.51387302", "0.81620973", "0.82433610", "0.18302488", "0.79048957", 522 | "0.07598187", "0.27887732", "0.37061042", "0.36441016", "0.93736882", 523 | "0.77480946", "0.02269132", "0.40309874", "0.16427650", "0.13969296", 524 | "0.57605029", "0.00242426", "0.56626691", "0.84390990", "0.87455806", 525 | "0.12321023", "0.87561663", "0.60431578", "0.35880839", "0.50426282", 526 | "0.50697689", "0.06631164", "0.14976092", "0.89356018", "0.91473662", 527 | "0.04235237", "0.50073724", "0.75969690", "0.91743994", "0.79352335", 528 | "0.58078351", "0.91819984", "0.53520520", "0.18267367", "0.05608828", 529 | "0.68315721", "0.27264599", "0.41245634", "0.69706222", "0.69666203", 530 | "0.08967342", "0.64081905", "0.22576796", "0.69315628", "0.53981640", 531 | "0.76059129", "0.56712344", "0.94318621", "0.44081094", "0.31699284", 532 | "0.29477911", "0.80069824", "0.28366921", "0.96718081", "0.85345644", 533 | "0.11681215", "0.47600710", "0.33448255", "0.31217271", "0.35469241", 534 | "0.59511650", "0.49583692", "0.48922303", "0.20215259", "0.60159380", 535 | "0.17882055", "0.77601258", "0.71020391", "0.41833503", "0.71522856", 536 | "0.87534517", "0.43703394", "0.43056077", "0.64828071", "0.43069441", 537 | "0.39356849", "0.32063367", "0.92788963", "0.16878266", "0.56762591", 538 | "0.56042446", "0.84958464", "0.79408949", "0.08220340", "0.13922856", 539 | "0.82529019", "0.27134959", "0.00278080", "0.66192389", "0.01782933", 540 | "0.95404763", "0.50787645", "0.85320521", "0.83690362", "0.83771227", 541 | "0.46268665", "0.31716742", "0.01716647", "0.68264674", "0.01789888", 542 | "0.30446846", "0.14942271", "0.26982182", "0.74933947", "0.50394161", 543 | "0.78444542", "0.40009256", "0.40333422", "0.16627342", "0.01898760", 544 | "0.04221829", "0.77960213", "0.66230976", "0.56015996", "0.49535426", 545 | "0.38536259", "0.40406773", "0.99930568", "0.00857945", "0.16158390", 546 | "0.64805163", "0.20237524", "0.59106326", "0.76968277", "0.96887042", 547 | "0.29264851", "0.97373775", "0.16767633", "0.33014482", "0.27426548", 548 | "0.10947014", "0.75920652", "0.37757457", "0.13125207", "0.00826451", 549 | "0.96684342", "0.69362226", "0.22763554", "0.20717541", "0.42112268", 550 | "0.22803038", "0.33481806", "0.14968742", "0.71598558", "0.55126711", 551 | "0.64518015", "0.65170197", "0.89103003", "0.72728361", "0.24485454", 552 | "0.09410780", "0.79818029", "0.54212409", "0.17790462", "0.64442619", 553 | "0.62193511", "0.51193256", "0.02848781", "0.05719604", "0.45795152", 554 | "0.03219332", "0.28310254", "0.85746127", "0.64890240", "0.20658356", 555 | "0.50946422", "0.80432490", "0.08354468", "0.09222723", "0.67455943", 556 | "0.44638771", "0.76366629", "0.99677267", "0.89311242", "0.11627279", 557 | "0.09181302", "0.44767077", "0.16448724", "0.26005539", "0.28670391", 558 | "0.52465703", "0.43598116", "0.41869096", "0.98043420", "0.01497272", 559 | "0.51791571", "0.61825308", "0.85503436", "0.63025655", "0.02719292", 560 | "0.09865668", "0.30321729", "0.56998039", "0.14946350", "0.64823918", 561 | "0.19931639", "0.14623555", "0.54169913", "0.68944135", "0.73551005", 562 | "0.46743658", "0.04109096", "0.26625801", "0.09537298", "0.98207890", 563 | "0.58109721", "0.70793680", "0.84379365", "0.42774726", "0.12653597", 564 | "0.08566633", "0.53366781", "0.33960092", "0.11036831", "0.84464510", 565 | "0.16493476", "0.92493443", "0.87640673", "0.52727644", "0.57181349", 566 | "0.65071340", "0.00978637", "0.31700693", "0.69148222", "0.85063311", 567 | "0.06781819", "0.30794534", "0.65541667", "0.16400484", "0.06886223", 568 | "0.96227205", "0.09633060", "0.34513153", "0.31013900", "0.78165882", 569 | "0.39583699", "0.86327936", "0.69269199", "0.11016575", "0.67358419", 570 | "0.81775427", "0.50052824", "0.30068582", "0.16606837", "0.62243724", 571 | "0.47863741", "0.68796498", "0.31526949", "0.41180883", "0.23022147", 572 | "0.82342139", "0.83003381", "0.53571829", "0.41081533", "0.48600142", 573 | }; 574 | } -------------------------------------------------------------------------------- /mt19937/go/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /mt19937/go/README.rst: -------------------------------------------------------------------------------- 1 | The Mersenne Twister in Go 2 | ========================== 3 | 4 | An implementation of Takuji Nishimura's and Makoto Matsumoto's 5 | `Mersenne Twister`_ pseudo random number generator in Go. 6 | 7 | Copyright (C) 2013 Jochen Voss 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | The homepage of this package is at . 15 | Please send any comments or bug reports to the program's author, 16 | Jochen Voss . 17 | 18 | .. _Mersenne Twister: http://en.wikipedia.org/wiki/Mersenne_twister 19 | 20 | Overview 21 | -------- 22 | 23 | The Mersenne Twister is a pseudo random number generator (PRNG), 24 | developed by Takuji Nishimura and Makoto Matsumoto. The Mersenne 25 | Twister is, for example, commonly used in Monte Carlo simulations and 26 | is the default random number generator for many programming languages, 27 | e.g. Python_ and R_. This package implements the `64bit version`_ of the 28 | algorithm. 29 | 30 | .. _Python: http://www.python.org/ 31 | .. _R: http://www.r-project.org/ 32 | .. _64bit version: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html 33 | 34 | 35 | Installation 36 | ------------ 37 | 38 | This package can be installed using the ``go get`` command:: 39 | 40 | go get github.com/seehuhn/mt19937 41 | 42 | 43 | Usage 44 | ----- 45 | 46 | Detailed usage instructions are available via the package's online 47 | help, either on godoc.org_ or on the command line:: 48 | 49 | go doc github.com/seehuhn/mt19937 50 | 51 | .. _godoc.org: http://godoc.org/github.com/seehuhn/mt19937 52 | 53 | The class ``MT19937`` represents instances of the Mersenne Twister. 54 | New instances can be allocated using the ``mt19937.New()`` function. 55 | A seed can be set using the .Seed() or .SeedFromSlice() methods. 56 | ``MT19937`` implements the ``rand.Source`` interface from the 57 | ``math/rand`` package. Typically the PRNG is wrapped in a rand.Rand 58 | object as in the following example:: 59 | 60 | rng := rand.New(mt19937.New()) 61 | rng.Seed(time.Now().UnixNano()) 62 | 63 | Comparison to the Go Default PRNG 64 | --------------------------------- 65 | 66 | Go has a built-in PRNG provided by the math/rand package. I did not 67 | find any information about this built-in PRNG except for a comment in 68 | the source code which says "algorithm by DP Mitchell and JA Reeds". 69 | In contrast, the MT19737 generator provided in this package is a 70 | well-understood random number generator. Relevant references include 71 | [Ni2000]_ and [MatNi1998]_. 72 | 73 | .. [Ni2000] T. Nishimura, *Tables of 64-bit Mersenne Twisters*, ACM 74 | Transactions on Modeling and Computer Simulation 10, 2000, pages 75 | 348-357. 76 | .. [MatNi1998] M. Matsumoto and T. Nishimura, *Mersenne Twister: a 77 | 623-dimensionally equidistributed uniform pseudorandom number 78 | generator*, ACM Transactions on Modeling and Computer Simulation 79 | 8, 1998, pages 3--30. 80 | 81 | The unit tests for the mt19937 package verify that the output of the 82 | Go implementation coincides with the output of the references 83 | implementation. 84 | 85 | The mt19937 generator is slightly slower than the Go default PRNG. 86 | A speed comparison can be performed using the following command:: 87 | 88 | go test -bench=. github.com/seehuhn/mt19937 89 | 90 | On my (64bit) system I get the following results: 91 | 92 | +----------------+---------------+----------------+ 93 | | method | time per call | thoughput | 94 | +================+===============+================+ 95 | | MT19937.Uint64 | 14.9 ns/op | 537.48 MB/s | 96 | +----------------+---------------+----------------+ 97 | | MT19937.Int63 | 15.0 ns/op | 533.54 MB/s | 98 | +----------------+---------------+----------------+ 99 | | builtin Int63 | 11.9 ns/op | 674.07 MB/s | 100 | +----------------+---------------+----------------+ 101 | 102 | This shows that, on my system, a call to the ``Int63()`` method of the 103 | built-in PRNG takes about 80% of the time that MT19937.Int63() takes. 104 | -------------------------------------------------------------------------------- /mt19937/go/doc.go: -------------------------------------------------------------------------------- 1 | // doc.go - package documentation for github.com/seehuhn/mt19937 2 | // Copyright (C) 2013 Jochen Voss 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | // Package mt19937 is a pure-go implementation of the 64bit Mersenne 18 | // Twister pseudo random number generator (PRNG). The Mersenne 19 | // Twister, developed by Takuji Nishimura and Makoto Matsumoto, is, 20 | // for example, commonly used in Monte Carlo simulations. The 21 | // implementation in the mt19937 package closely follows the reference 22 | // implementation from 23 | // 24 | // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html 25 | // 26 | // and, for identical seeds, gives identical output to the reference 27 | // implementation. 28 | // 29 | // The PRNG from the mt19937 package implements the rand.Source 30 | // interface from the math/rand package. Typically the PRNG is 31 | // wrapped in a rand.Rand object as in the following example: 32 | // 33 | // rng := rand.New(mt19937.New()) 34 | // rng.Seed(time.Now().UnixNano()) 35 | package mt19937 36 | -------------------------------------------------------------------------------- /mt19937/go/example.go: -------------------------------------------------------------------------------- 1 | // example.go - a test program for the mt19937 package 2 | // Copyright (C) 2013 Jochen Voss 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | // +build ignore 18 | 19 | package main 20 | 21 | import ( 22 | "fmt" 23 | "github.com/funny/mt19937/go" 24 | "math/rand" 25 | "time" 26 | ) 27 | 28 | func main() { 29 | rng := rand.New(mt19937.New()) 30 | rng.Seed(time.Now().UnixNano()) 31 | fmt.Println(rng.NormFloat64()) 32 | } 33 | -------------------------------------------------------------------------------- /mt19937/go/mt19937.go: -------------------------------------------------------------------------------- 1 | // mt19937.go - an implementation of the 64bit Mersenne Twister PRNG 2 | // Copyright (C) 2013 Jochen Voss 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | package mt19937 18 | 19 | const ( 20 | n = 312 21 | m = 156 22 | notSeeded = n + 1 23 | 24 | hiMask uint64 = 0xffffffff80000000 25 | loMask uint64 = 0x000000007fffffff 26 | 27 | matrixA uint64 = 0xB5026F5AA96619E9 28 | ) 29 | 30 | // MT19937 is the structure to hold the state of one instance of the 31 | // Mersenne Twister PRNG. New instances can be allocated using the 32 | // mt19937.New() function. MT19937 implements the rand.Source 33 | // interface and rand.New() from the math/rand package can be used to 34 | // generate different distributions from a MT19937 PRNG. 35 | // 36 | // This class is not safe for concurrent accesss by different 37 | // goroutines. If more than one goroutine accesses the PRNG, the 38 | // callers must synchronise access using sync.Mutex or similar. 39 | type MT19937 struct { 40 | state []uint64 41 | index int 42 | } 43 | 44 | // New allocates a new instance of the 64bit Mersenne Twister. 45 | // A seed can be set using the .Seed() or .SeedFromSlice() methods. 46 | func New() *MT19937 { 47 | res := &MT19937{ 48 | state: make([]uint64, n), 49 | index: notSeeded, 50 | } 51 | return res 52 | } 53 | 54 | // Seed uses the given 64bit value to initialise the generator state. 55 | // This method is part of the rand.Source interface. 56 | func (mt *MT19937) Seed(seed int64) { 57 | x := mt.state 58 | x[0] = uint64(seed) 59 | for i := uint64(1); i < n; i++ { 60 | x[i] = 6364136223846793005*(x[i-1]^(x[i-1]>>62)) + i 61 | } 62 | mt.index = n 63 | } 64 | 65 | // SeedFromSlice uses the given slice of 64bit values to set the 66 | // generator state. 67 | func (mt *MT19937) SeedFromSlice(key []uint64) { 68 | mt.Seed(19650218) 69 | 70 | x := mt.state 71 | i := uint64(1) 72 | j := 0 73 | k := len(key) 74 | if n > k { 75 | k = n 76 | } 77 | for k > 0 { 78 | x[i] = (x[i] ^ ((x[i-1] ^ (x[i-1] >> 62)) * 3935559000370003845) + key[j] + uint64(j)) 79 | i++ 80 | if i >= n { 81 | x[0] = x[n-1] 82 | i = 1 83 | } 84 | j++ 85 | if j >= len(key) { 86 | j = 0 87 | } 88 | k-- 89 | } 90 | for j := uint64(0); j < n-1; j++ { 91 | x[i] = x[i] ^ ((x[i-1] ^ (x[i-1] >> 62)) * 2862933555777941757) - i 92 | i++ 93 | if i >= n { 94 | x[0] = x[n-1] 95 | i = 1 96 | } 97 | } 98 | x[0] = 1 << 63 99 | } 100 | 101 | // Uint64 generates a (pseudo-)random 64bit value. The output can be 102 | // used as a replacement for a sequence of independent, uniformly 103 | // distributed samples in the range 0, 1, ..., 2^64-1. 104 | func (mt *MT19937) Uint64() uint64 { 105 | x := mt.state 106 | if mt.index >= n { 107 | if mt.index == notSeeded { 108 | mt.Seed(5489) // default seed, as in mt19937-64.c 109 | } 110 | for i := 0; i < n-m; i++ { 111 | y := (x[i] & hiMask) | (x[i+1] & loMask) 112 | x[i] = x[i+m] ^ (y >> 1) ^ ((y & 1) * matrixA) 113 | } 114 | for i := n - m; i < n-1; i++ { 115 | y := (x[i] & hiMask) | (x[i+1] & loMask) 116 | x[i] = x[i+(m-n)] ^ (y >> 1) ^ ((y & 1) * matrixA) 117 | } 118 | y := (x[n-1] & hiMask) | (x[0] & loMask) 119 | x[n-1] = x[m-1] ^ (y >> 1) ^ ((y & 1) * matrixA) 120 | mt.index = 0 121 | } 122 | y := x[mt.index] 123 | y ^= (y >> 29) & 0x5555555555555555 124 | y ^= (y << 17) & 0x71D67FFFEDA60000 125 | y ^= (y << 37) & 0xFFF7EEE000000000 126 | y ^= (y >> 43) 127 | mt.index++ 128 | return y 129 | } 130 | 131 | // Int63 generates a (pseudo-)random 63bit value. The output can be 132 | // used as a replacement for a sequence of independent, uniformly 133 | // distributed samples in the range 0, 1, ..., 2^63-1. This method is 134 | // part of the rand.Source interface. 135 | func (mt *MT19937) Int63() int64 { 136 | return int64(mt.Uint64() >> 1) 137 | } 138 | 139 | func (mt *MT19937) Real1() float64 { 140 | return float64(mt.Uint64()>>11) * (1.0 / 9007199254740991.0) 141 | } 142 | 143 | func (mt *MT19937) Real2() float64 { 144 | return float64(mt.Uint64()>>11) * (1.0 / 9007199254740992.0) 145 | } 146 | 147 | func (mt *MT19937) Real3() float64 { 148 | return (float64(mt.Uint64()>>12) + 0.5) * (1.0 / 4503599627370496.0) 149 | } 150 | -------------------------------------------------------------------------------- /mt19937/go/mt19937_test.go: -------------------------------------------------------------------------------- 1 | // mt19937_test.go - unit tests for mt19937.go 2 | // Copyright (C) 2013 Jochen Voss 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | package mt19937 18 | 19 | import ( 20 | "fmt" 21 | "math/rand" 22 | "testing" 23 | ) 24 | 25 | // This is the output of the mt19937ar.c program from 26 | // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html 27 | var expectedInt = []uint64{ 28 | 7266447313870364031, 4946485549665804864, 16945909448695747420, 29 | 16394063075524226720, 4873882236456199058, 14877448043947020171, 30 | 6740343660852211943, 13857871200353263164, 5249110015610582907, 31 | 10205081126064480383, 1235879089597390050, 17320312680810499042, 32 | 16489141110565194782, 8942268601720066061, 13520575722002588570, 33 | 14226945236717732373, 9383926873555417063, 15690281668532552105, 34 | 11510704754157191257, 15864264574919463609, 6489677788245343319, 35 | 5112602299894754389, 10828930062652518694, 15942305434158995996, 36 | 15445717675088218264, 4764500002345775851, 14673753115101942098, 37 | 236502320419669032, 13670483975188204088, 14931360615268175698, 38 | 8904234204977263924, 12836915408046564963, 12120302420213647524, 39 | 15755110976537356441, 5405758943702519480, 10951858968426898805, 40 | 17251681303478610375, 4144140664012008120, 18286145806977825275, 41 | 13075804672185204371, 10831805955733617705, 6172975950399619139, 42 | 12837097014497293886, 12903857913610213846, 560691676108914154, 43 | 1074659097419704618, 14266121283820281686, 11696403736022963346, 44 | 13383246710985227247, 7132746073714321322, 10608108217231874211, 45 | 9027884570906061560, 12893913769120703138, 15675160838921962454, 46 | 2511068401785704737, 14483183001716371453, 3774730664208216065, 47 | 5083371700846102796, 9583498264570933637, 17119870085051257224, 48 | 5217910858257235075, 10612176809475689857, 1924700483125896976, 49 | 7171619684536160599, 10949279256701751503, 15596196964072664893, 50 | 14097948002655599357, 615821766635933047, 5636498760852923045, 51 | 17618792803942051220, 580805356741162327, 425267967796817241, 52 | 8381470634608387938, 13212228678420887626, 16993060308636741960, 53 | 957923366004347591, 6210242862396777185, 1012818702180800310, 54 | 15299383925974515757, 17501832009465945633, 17453794942891241229, 55 | 15807805462076484491, 8407189590930420827, 974125122787311712, 56 | 1861591264068118966, 997568339582634050, 18046771844467391493, 57 | 17981867688435687790, 3809841506498447207, 9460108917638135678, 58 | 16172980638639374310, 958022432077424298, 4393365126459778813, 59 | 13408683141069553686, 13900005529547645957, 15773550354402817866, 60 | 16475327524349230602, 6260298154874769264, 12224576659776460914, 61 | 6405294864092763507, 7585484664713203306, 5187641382818981381, 62 | 12435998400285353380, 13554353441017344755, 646091557254529188, 63 | 11393747116974949255, 16797249248413342857, 15713519023537495495, 64 | 12823504709579858843, 4738086532119935073, 4429068783387643752, 65 | 585582692562183870, 1048280754023674130, 6788940719869959076, 66 | 11670856244972073775, 2488756775360218862, 2061695363573180185, 67 | 6884655301895085032, 3566345954323888697, 12784319933059041817, 68 | 4772468691551857254, 6864898938209826895, 7198730565322227090, 69 | 2452224231472687253, 13424792606032445807, 10827695224855383989, 70 | 11016608897122070904, 14683280565151378358, 7077866519618824360, 71 | 17487079941198422333, 3956319990205097495, 5804870313319323478, 72 | 8017203611194497730, 3310931575584983808, 5009341981771541845, 73 | 6930001938490791874, 14415278059151389495, 11001114762641844083, 74 | 6715939435439735925, 411419160297131328, 4522402260441335284, 75 | 3381955501804126859, 15935778656111987797, 4345051260540166684, 76 | 13978444093099579683, 9219789505504949817, 9245142924137529075, 77 | 11628184459157386459, 7242398879359936370, 8511401943157540109, 78 | 11948130810477009827, 6865450671488705049, 13965005347172621081, 79 | 15956599226522058336, 7737868921014130584, 2107342503741411693, 80 | 15818996300425101108, 16399939197527488760, 13971145494081508107, 81 | 3910681448359868691, 4249175367970221090, 9735751321242454020, 82 | 12418107929362160460, 241792245481991138, 5806488997649497146, 83 | 10724207982663648949, 1121862814449214435, 1326996977123564236, 84 | 4902706567834759475, 12782714623891689967, 7306216312942796257, 85 | 15681656478863766664, 957364844878149318, 5651946387216554503, 86 | 8197027112357634782, 6302075516351125977, 13454588464089597862, 87 | 15638309200463515550, 10116604639722073476, 12052913535387714920, 88 | 2889379661594013754, 15383926144832314187, 7841953313015471731, 89 | 17310575136995821873, 9820021961316981626, 15319619724109527290, 90 | 15349724127275899898, 10511508162402504492, 6289553862380300393, 91 | 15046218882019267110, 11772020174577005930, 3537640779967351792, 92 | 6801855569284252424, 17687268231192623388, 12968358613633237218, 93 | 1429775571144180123, 10427377732172208413, 12155566091986788996, 94 | 16465954421598296115, 12710429690464359999, 9547226351541565595, 95 | 12156624891403410342, 2985938688676214686, 18066917785985010959, 96 | 5975570403614438776, 11541343163022500560, 11115388652389704592, 97 | 9499328389494710074, 9247163036769651820, 3688303938005101774, 98 | 2210483654336887556, 15458161910089693228, 6558785204455557683, 99 | 1288373156735958118, 18433986059948829624, 3435082195390932486, 100 | 16822351800343061990, 3120532877336962310, 16681785111062885568, 101 | 7835551710041302304, 2612798015018627203, 15083279177152657491, 102 | 6591467229462292195, 10592706450534565444, 7438147750787157163, 103 | 323186165595851698, 7444710627467609883, 8473714411329896576, 104 | 2782675857700189492, 3383567662400128329, 3200233909833521327, 105 | 12897601280285604448, 3612068790453735040, 8324209243736219497, 106 | 15789570356497723463, 1083312926512215996, 4797349136059339390, 107 | 5556729349871544986, 18266943104929747076, 1620389818516182276, 108 | 172225355691600141, 3034352936522087096, 1266779576738385285, 109 | 3906668377244742888, 6961783143042492788, 17159706887321247572, 110 | 4676208075243319061, 10315634697142985816, 13435140047933251189, 111 | 716076639492622016, 13847954035438697558, 7195811275139178570, 112 | 10815312636510328870, 6214164734784158515, 16412194511839921544, 113 | 3862249798930641332, 1005482699535576005, 4644542796609371301, 114 | 17600091057367987283, 4209958422564632034, 5419285945389823940, 115 | 11453701547564354601, 9951588026679380114, 7425168333159839689, 116 | 8436306210125134906, 11216615872596820107, 3681345096403933680, 117 | 5770016989916553752, 11102855936150871733, 11187980892339693935, 118 | 396336430216428875, 6384853777489155236, 7551613839184151117, 119 | 16527062023276943109, 13429850429024956898, 9901753960477271766, 120 | 9731501992702612259, 5217575797614661659, 10311708346636548706, 121 | 15111747519735330483, 4353415295139137513, 1845293119018433391, 122 | 11952006873430493561, 3531972641585683893, 16852246477648409827, 123 | 15956854822143321380, 12314609993579474774, 16763911684844598963, 124 | 16392145690385382634, 1545507136970403756, 17771199061862790062, 125 | 12121348462972638971, 12613068545148305776, 954203144844315208, 126 | 1257976447679270605, 3664184785462160180, 2747964788443845091, 127 | 15895917007470512307, 15552935765724302120, 16366915862261682626, 128 | 8385468783684865323, 10745343827145102946, 2485742734157099909, 129 | 916246281077683950, 15214206653637466707, 12895483149474345798, 130 | 1079510114301747843, 10718876134480663664, 1259990987526807294, 131 | 8326303777037206221, 14104661172014248293, 15531278677382192198, 132 | 3874303698666230242, 3611366553819264523, 1358753803061653874, 133 | 1552102816982246938, 14492630642488100979, 15001394966632908727, 134 | 2273140352787320862, 17843678642369606172, 2903980458593894032, 135 | 16971437123015263604, 12969653681729206264, 3593636458822318001, 136 | 9719758956915223015, 7437601263394568346, 3327758049015164431, 137 | 17851524109089292731, 14769614194455139039, 8017093497335662337, 138 | 12026985381690317404, 739616144640253634, 15535375191850690266, 139 | 2418267053891303448, 15314073759564095878, 10333316143274529509, 140 | 16565481511572123421, 16317667579273275294, 13991958187675987741, 141 | 3753596784796798785, 9078249094693663275, 8459506356724650587, 142 | 12579909555010529099, 7827737296967050903, 5489801927693999341, 143 | 10995988997350541459, 14721747867313883304, 7915884580303296560, 144 | 4105766302083365910, 12455549072515054554, 13602111324515032467, 145 | 5205971628932290989, 5034622965420036444, 9134927878875794005, 146 | 11319873529597990213, 14815445109496752058, 2266601052460299470, 147 | 5696993487088103383, 6540200741841280242, 6631495948031875490, 148 | 5328340585170897740, 17897267040961463930, 9030000260502624168, 149 | 14285709137129830926, 12854071997824681544, 15408328651008978682, 150 | 1063314403033437073, 13765209628446252802, 242013711116865605, 151 | 4772374239432528212, 2515855479965038648, 5872624715703151235, 152 | 14237704570091006662, 678604024776645862, 12329607334079533339, 153 | 17570877682732917020, 2695443415284373666, 4312672841405514468, 154 | 6454343485137106900, 8425658828390111343, 16335501385875554899, 155 | 5551095603809016713, 11781094401885925035, 9395557946368382509, 156 | 9765123360948816956, 18107191819981188154, 16049267500594757404, 157 | 16349966108299794199, 1040405303135858246, 2366386386131378192, 158 | 223761048139910454, 15375217587047847934, 15231693398695187454, 159 | 12916726640254571028, 8878036960829635584, 1626201782473074365, 160 | 5758998126998248293, 18077917959300292758, 10585588923088536745, 161 | 15072345664541731497, 3559348759319842667, 12744591691872202375, 162 | 2388494115860283059, 6414691845696331748, 3069528498807764495, 163 | 8737958486926519702, 18059264986425101074, 3139684427605102737, 164 | 12378931902986734693, 410666675039477949, 12139894855769838924, 165 | 5780722552400398675, 7039346665375142557, 3020733445712569008, 166 | 2612305843503943561, 13651771214166527665, 16478681918975800939, 167 | 566088527565499576, 4715785502295754870, 6957318344287196220, 168 | 11645756868405128885, 13139951104358618000, 17650948583490040612, 169 | 18168787973649736637, 5486282999836125542, 6122201977153895166, 170 | 17324241605502052782, 10063523107521105867, 17537430712468011382, 171 | 10828407533637104262, 10294139354198325113, 12557151830240236401, 172 | 16673044307512640231, 10918020421896090419, 11077531235278014145, 173 | 5499571814940871256, 2334252435740638702, 18177461912527387031, 174 | 2000007376901262542, 7968425560071444214, 1472650787501520648, 175 | 3115849849651526279, 7980970700139577536, 12153253535907642097, 176 | 8109716914843248719, 3154976533165008908, 5553369513523832559, 177 | 10345792701798576501, 3677445364544507875, 10637177623943913351, 178 | 7380255087060498096, 14479400372337014801, 15381362583330700960, 179 | 204531043189704802, 13699106540959723942, 3817903465872254783, 180 | 10972364467110284934, 2701394334530963810, 2931625600749229147, 181 | 16428252083632828910, 11873166501966812913, 5566810080537233762, 182 | 7840617383807795056, 10699413880206684652, 18259119259617231436, 183 | 10332714341486317526, 10137911902863059694, 669146221352346842, 184 | 8373571610024623455, 10620002450820868661, 12220730820779815970, 185 | 5902974968095412898, 7931010481705150841, 16413777368097063650, 186 | 11273457888324769727, 13719113891065284171, 8327795098009702553, 187 | 10333342364827584837, 6202832891413866653, 9137034567886143162, 188 | 14514450826524340059, 473610156015331016, 813689571029117640, 189 | 13776316799690285717, 10429708855338427756, 8995290140880620858, 190 | 2320123852041754384, 8082864073645003641, 6961777411740398590, 191 | 10008644283003991179, 3239064015890722333, 16762634970725218787, 192 | 16467281536733948427, 10563290046315192938, 5108560603794851559, 193 | 15121667220761532906, 14155440077372845941, 10050536352394623377, 194 | 15474881667376037792, 3448088038819200619, 3692020001240358871, 195 | 6444847992258394902, 8687650838094264665, 3028124591188972359, 196 | 16945232313401161629, 15547830510283682816, 3982930188609442149, 197 | 14270781928849894661, 13768475593433447867, 13815150225221307677, 198 | 8502397232429564693, 718377350715476994, 7459266877697905475, 199 | 8353375565171101521, 7807281661994435472, 16924127046922196149, 200 | 10157812396471387805, 2519858716882670232, 7384148884750265792, 201 | 8077153156180046901, 3499231286164597752, 2700106282881469611, 202 | 14679824700835879737, 14188324938219126828, 3016120398601032793, 203 | 10858152824243889420, 9412371965669250534, 4857522662584941069, 204 | 984331743838900386, 4094160040294753142, 2368635764350388458, 205 | 15101240511397838657, 15584415763303953578, 7831857200208015446, 206 | 1952643641639729063, 4184323302594028609, 16795120381104846695, 207 | 3541559381538365280, 15408472870896842474, 5628362450757896366, 208 | 16277348886873708846, 12437047172652330846, 10172715019035948149, 209 | 1999700669649752791, 6217957085626135027, 11220551167830336823, 210 | 16478747645632411810, 5437280487207382147, 11382378739613087836, 211 | 15866932785489521505, 5502694314775516684, 16440179278067648435, 212 | 15510104554374162846, 15722061259110909195, 10760687291786964354, 213 | 10736868329920212671, 4166148127664495614, 14303518358120527892, 214 | 9122250801678898571, 10028508179936801946, 216630713752669403, 215 | 10655207865433859491, 4041437116174699233, 6280982262534375348, 216 | 297501356638818866, 13976146806363377485, 13752396481560145603, 217 | 11472199956603637419, 16393728429143900496, 14752844047515986640, 218 | 1524477318846038424, 6596889774254235440, 1591982099532234960, 219 | 8065146456116391065, 3964696017750868345, 17040425970526664920, 220 | 11511165586176539991, 3443401252003315103, 16314977947073778249, 221 | 16860120454903458341, 5370503221561340846, 15362920279125264094, 222 | 2822458124714999779, 14575378304387898337, 9689406052675046032, 223 | 2872149351415175149, 13019620945255883050, 14929026760148695825, 224 | 8503417349692327218, 9677798905341573754, 828949921821462483, 225 | 16110482368362750196, 15794218816553655671, 14942910774764855088, 226 | 12026350906243760195, 13610867176871462505, 18324536557697872582, 227 | 2658962269666727629, 327225403251576027, 9207535177029277544, 228 | 8744129291351887858, 6129603385168921503, 18385497655031085907, 229 | 13024478718952333892, 14547683159720717167, 5932119629366981711, 230 | 325385464632594563, 3559879386019806291, 6629264948665231298, 231 | 14358245326238118181, 15662449672706340765, 13975503159145803297, 232 | 3609534220891499022, 4224273587485638227, 9274084767162416370, 233 | 13156843921244091998, 18284750575626858789, 14664767920489118779, 234 | 11292057742031803221, 13919998707305829132, 14473305049457001422, 235 | 9696877879685767807, 1406758246007973837, 2429517644459056881, 236 | 14361215588101587430, 11386164476149757528, 10474116023593331839, 237 | 2921165656527786564, 15604610369733358953, 12955027028676000544, 238 | 10314281035410779907, 3167047178514709947, 1088721329408346700, 239 | 17930425515478182741, 7466411836095405617, 15534027454610690575, 240 | 10879629128927506091, 11502219301371200635, 13915106894453889418, 241 | 4226784327815861027, 12335222183627106346, 3648499746356007767, 242 | 18441388887898023393, 18117929843327093625, 4237736098094830438, 243 | 14229123019768296655, 3930112058127932690, 12663879236019645778, 244 | 9281161952002617309, 4978473890680876319, 845759387067546611, 245 | 1386164484606776333, 8008554770639925512, 11159581016793288971, 246 | 18065390393740782906, 17647985458967631018, 9092379465737744314, 247 | 2914678236848656327, 4376066698447630270, 16057186499919087528, 248 | 3031333261848790078, 2926746602873431597, 7931945763526885287, 249 | 147649915388326849, 15801792398814946230, 5265900391686545347, 250 | 16173686275871890830, 7562781050481886043, 5853506575839330404, 251 | 14957980734704564792, 10944286556353523404, 1783009880614150597, 252 | 9529762028588888983, 822992871011696119, 2130074274744257510, 253 | 8000279549284809219, 3514744284158856431, 128770032569293263, 254 | 3737367602618100572, 16364836605077998543, 783266423471782696, 255 | 4569418252658970391, 11093950688157406886, 14888808512267628166, 256 | 4217786261273670948, 17047486076688645713, 14133826721458860485, 257 | 17539744882220127106, 12394675039129853905, 5757634999463277090, 258 | 9621947619435861331, 1182210208559436772, 14603391040490913939, 259 | 17481976703660945893, 14063388816234683976, 2046622692581829572, 260 | 8294969799792017441, 5293778434844788058, 17976364049306763808, 261 | 399482430848083948, 16495545010129798933, 15241340958282367519, 262 | 989828753826900814, 17616558773874893537, 2471817920909589004, 263 | 11764082277667899978, 9618755269550400950, 1240014743757147125, 264 | 1887649378641563002, 1842982574728131416, 13243531042427194002, 265 | 7688268125537013927, 3080422097287486736, 2562894809975407783, 266 | 12428984115620094788, 1355581933694478148, 9895969242586224966, 267 | 8628445623963160889, 4298916726468199239, 12773165416305557280, 268 | 5240726258301567487, 4975412836403427561, 1842172398579595303, 269 | 7812151462958058676, 17974510987263071769, 14980707022065991200, 270 | 18294903201142729875, 12911672684850242753, 8979482998667235743, 271 | 16808468362384462073, 5981317232108359798, 12373702800369335100, 272 | 16119707581920094765, 2782738549717633602, 15454155188515389391, 273 | 16495638000603654629, 16348757069342790497, 7769562861984504567, 274 | 17504300515449231559, 5557710032938318996, 11846125204788401203, 275 | 13957316349928882624, 2738350683717432043, 15738068448047700954, 276 | 6224714837294524999, 6081930777706411111, 11366312928059597928, 277 | 4355315799925031482, 12393324728734964015, 15277140291994338591, 278 | 1406052433297386355, 15859448364509213398, 1672805458341158435, 279 | 2926095111610982994, 11056431822276774455, 12083767323511977430, 280 | 3296968762229741153, 12312076899982286460, 17769284994682227273, 281 | 15349428916826953443, 1056147296359223910, 18305757538706977431, 282 | 6214378374180465222, 14279648441175008454, 17791306410319136644, 283 | 956593013486324072, 2921235772936241950, 10002890515925652606, 284 | 10399654693663712506, 6446247931049971441, 6380465770144534958, 285 | 11439178472613251620, 10131486500045494660, 3692642123868351947, 286 | 10972816599561388940, 4931112976348785580, 8213967169213816566, 287 | 15336469859637867841, 15026830342847689383, 7524668622380765825, 288 | 17309937346758783807, 372780684412666438, 5642417144539399955, 289 | 18303842993081194577, 11085303253831702827, 15658163165983586950, 290 | 8517521928922081563, 16091186344159989860, 17614656488010863910, 291 | 4736067146481515156, 13449945221374241354, 17755469346196579408, 292 | 13300502638545717375, 6611828134763118043, 14177591906740276597, 293 | 9340430243077460347, 7499765399826404087, 3409518087967832469, 294 | 9013253864026602045, 4444307427984430192, 3729283608700519712, 295 | 13642048880719588383, 16486557958022946240, 2996465014991157904, 296 | 10020049344596426576, 12302485648009883778, 8492591321344423126, 297 | 17407986443716172520, 10530482934957373052, 15740662350540828750, 298 | 1790629986901049436, 6305948377669917188, 15092985352503125323, 299 | 928505047232899787, 14404651977039851607, 7564177565277805597, 300 | 3411236815351677870, 7752718145953236134, 12315979971311483798, 301 | 12477729506691004724, 14654956300924793305, 6689803038918974388, 302 | 1540738812233000153, 13508351811701989957, 15864432023192136053, 303 | 7990997967273843917, 7424300239290765161, 39585249496300263, 304 | 3877436595063283319, 10710642254398044448, 4653804418844456375, 305 | 1232267496410380283, 3690525514009038824, 15459770765077428485, 306 | 13240346522153894145, 5674964360688390624, 16973644653010587289, 307 | 15924280764204855206, 15196708627253442662, 17596174821341373274, 308 | 16196745023027393691, 6980050627399795351, 17582264380857746637, 309 | 18170372407506856324, 12108126025631005514, 15687749089493373169, 310 | 5814107289258228434, 9381977959648494876, 15895601183088112734, 311 | 16267869075651604263, 15228381979765852785, 11949618678312581999, 312 | 4545324791131029438, 582725409406225185, 15282520250746126790, 313 | 14758446535973412711, 7605613563088071833, 1111140641057375915, 314 | 5364843095234852245, 218335432181198977, 4891472444796201742, 315 | 4564628942836375772, 15500501278323817088, 4913946328556108657, 316 | 2684786251736694229, 12090498456116310122, 5310885782157038567, 317 | 5032788439854011923, 12627401038822728242, 11869662610126430929, 318 | 17650156853043540226, 12126672500118808436, 10437658933435653256, 319 | 13133995470637873311, 4601324715591152820, 1874350460376708372, 320 | 5808688626286061164, 13777088437302430376, 5018451954762213522, 321 | 2588296738534474754, 5503414509154170711, 5230497186769951796, 322 | 13261090710400573914, 8515217303152165705, 11074538219737365303, 323 | 15481562385740613213, 12705484409881007350, 14221931471178549498, 324 | 12905633420087112297, 17337759164357146506, 14081997515778175224, 325 | 17384320185513122939, 7131793076779216692, 17483217190312403109, 326 | 900692047897995877, 14723287313048560400, 6132094372965340305, 327 | 7572797575350925726, 12725160700431903514, 380860122911632449, 328 | 1900504978569024571, 8423729759529914138, 7305587201606052334, 329 | 12446871355267313320, 4615812356515386206, 3361817115406652303, 330 | 17690418922000878428, 14632214537567910559, 2709702289926174775, 331 | 3459675155951086144, 7788364399926538150, 16043992474431955950, 332 | 15830963823784930267, 4216893617835797954, 538159724689093771, 333 | 16029152738918251363, 14444848757576686696, 12941757045272633696, 334 | 10900480525147953314, 12547307449905859302, 16001571796892398181, 335 | 407942194622690676, 13873235372903944444, 18071603799493008777, 336 | 1015646077646778622, 9387605808959554815, 11566702442022019410, 337 | 7061722181092883183, 2629032108249254109, 5271820053177594520, 338 | 12640880742139693547, 10098688629735675775, 5716304472850923064, 339 | 3312674502353063071, 7295926377425759633, 833281439103466115, 340 | 16316743519466861667, 9912050326606348167, 11651133878100804242, 341 | 18026798122431692459, 6157758321723692663, 4856021830695749349, 342 | 7074321707293278978, 10748097797809573561, 2949954440753264783, 343 | 9813922580940661152, 9949237950172138336, 15643982711269455885, 344 | 16078663425810239127, 12508044395364228880, 12920301578340189344, 345 | 15368071871011048915, 1610400750626363239, 11994736084146033126, 346 | 6042574085746186088, 4154587549267685807, 15915752367312946034, 347 | 1191196620621769193, 467437822242538360, 2836463788873877488, 348 | 10476401302029164984, 1716169985450737419, 5327734953288310341, 349 | 3994170067185955262, 884431883768190063, 11019001754831208284, 350 | 14322807384384895215, 161011537360955545, 1466223959660131656, 351 | 5227048585229497539, 12410731857504225031, 2142243279080761103, 352 | 17682826799106851430, 1792612570704179953, 14727410295243056025, 353 | 1459567192481221274, 5669760721687603135, 17507918443756456845, 354 | 10354471145847018200, 10362475129248202288, 13143844410150939443, 355 | 6861184673150072028, 18396524361124732580, 543906666394301875, 356 | 12476817828199026728, 11853496871128122868, 12747674713108891748, 357 | 7986179867749890282, 9158195177777627533, 2217320706811118570, 358 | 8631389005200569973, 5538133061362648855, 3369942850878700758, 359 | 7813559982698427184, 509051590411815948, 10197035660403006684, 360 | 13004818533162292132, 9831652587047067687, 7619315254749630976, 361 | 994412663058993407, 362 | } 363 | 364 | var expectedReal = []string{ 365 | "0.35252031", "0.51052342", "0.79771733", "0.39300273", "0.27216673", 366 | "0.72151068", "0.43144703", "0.38522290", "0.20270676", "0.58227313", 367 | "0.80812143", "0.83767297", "0.92401619", "0.84065425", "0.00852052", 368 | "0.13975395", "0.35250930", "0.71196972", "0.14627395", "0.17775331", 369 | "0.61046382", "0.49623272", "0.23292425", "0.25038837", "0.04380664", 370 | "0.43275994", "0.74540936", "0.33830700", "0.68832616", "0.68744230", 371 | "0.63626548", "0.85932936", "0.37089670", "0.50756304", "0.69925960", 372 | "0.83481025", "0.09053196", "0.09523253", "0.17783108", "0.78027239", 373 | "0.70071054", "0.51879252", "0.83027285", "0.92895011", "0.72144803", 374 | "0.18868644", "0.83655674", "0.20358945", "0.99852143", "0.88340103", 375 | "0.46729949", "0.96993433", "0.00162682", "0.46829774", "0.59080423", 376 | "0.54921999", "0.42516462", "0.54952196", "0.99534722", "0.04473888", 377 | "0.71139235", "0.91881407", "0.33781561", "0.45746234", "0.78292126", 378 | "0.69206723", "0.66175448", "0.07091147", "0.18179208", "0.38168454", 379 | "0.38819527", "0.42452711", "0.22732724", "0.16191307", "0.36842667", 380 | "0.13060083", "0.68833248", "0.60498705", "0.19195304", "0.26628584", 381 | "0.17030858", "0.23892426", "0.38430236", "0.28034283", "0.76069020", 382 | "0.21560653", "0.78101667", "0.90847812", "0.06467974", "0.18487868", 383 | "0.23570471", "0.29475460", "0.65563767", "0.10066446", "0.57272419", 384 | "0.88731391", "0.60650995", "0.96346079", "0.32940100", "0.29977746", 385 | "0.03798193", "0.18026822", "0.22402746", "0.45480119", "0.98114604", 386 | "0.25800668", "0.94362433", "0.17901062", "0.36019313", "0.45933644", 387 | "0.68309457", "0.28175454", "0.00774729", "0.77054527", "0.99723413", 388 | "0.59807532", "0.10294164", "0.32429228", "0.54928986", "0.18410980", 389 | "0.08441555", "0.14230333", "0.58892064", "0.94030475", "0.35378784", 390 | "0.77584320", "0.71222448", "0.83565208", "0.47309248", "0.23810761", 391 | "0.74408520", "0.08891527", "0.09729786", "0.38377368", "0.05092308", 392 | "0.69065638", "0.10449489", "0.45050670", "0.92209534", "0.80083714", 393 | "0.27902692", "0.26897142", "0.50650468", "0.80111472", "0.54590012", 394 | "0.96406097", "0.63779553", "0.81054357", "0.75369248", "0.47473037", 395 | "0.89100315", "0.89395984", "0.09985519", "0.34087631", "0.22293557", 396 | "0.24375510", "0.31764191", "0.04076993", "0.06160830", "0.41333434", 397 | "0.11883030", "0.04548820", "0.01008040", "0.25336184", "0.07325432", 398 | "0.49860151", "0.07148695", "0.89483338", "0.87054457", "0.15116809", 399 | "0.59650469", "0.47487776", "0.43490298", "0.36684681", "0.16470796", 400 | "0.76865078", "0.42920071", "0.20545481", "0.87615922", "0.80332404", 401 | "0.36462506", "0.49571309", "0.51904488", "0.15534589", "0.43719893", 402 | "0.16562157", "0.37290862", "0.91842631", "0.21310523", "0.87849154", 403 | "0.18532269", "0.81713354", "0.52182344", "0.51845619", "0.96261204", 404 | "0.18758718", "0.68897600", "0.61484764", "0.46752993", "0.05865458", 405 | "0.11614359", "0.90386866", "0.45781805", "0.70649579", "0.50917048", 406 | "0.21210656", "0.97818608", "0.00788342", "0.61375222", "0.67366318", 407 | "0.24197878", "0.66177985", "0.10463932", "0.67390799", "0.50025262", 408 | "0.88332650", "0.77966851", "0.13403622", "0.54357114", "0.97664854", 409 | "0.06540961", "0.24013176", "0.67234032", "0.91347883", "0.35486839", 410 | "0.87207865", "0.43036581", "0.23652488", "0.81238450", "0.72058432", 411 | "0.42239916", "0.80265764", "0.03552838", "0.61939480", "0.50972420", 412 | "0.21053832", "0.59952743", "0.36821802", "0.45659617", "0.12529468", 413 | "0.76941623", "0.99878168", "0.08602783", "0.81825937", "0.39350710", 414 | "0.86090923", "0.36090230", "0.75628888", "0.45036982", "0.44602266", 415 | "0.20595631", "0.62241953", "0.36777732", "0.47523727", "0.50248178", 416 | "0.73570362", "0.48237781", "0.45590948", "0.73580783", "0.96403851", 417 | "0.94586342", "0.48819868", "0.48102038", "0.94618182", "0.90279924", 418 | "0.78396650", "0.85182389", "0.92149394", "0.32679198", "0.83554856", 419 | "0.28320609", "0.34598409", "0.82090005", "0.40177958", "0.38888785", 420 | "0.77873931", "0.23297931", "0.75329335", "0.30770340", "0.71417540", 421 | "0.68939065", "0.36577776", "0.50784857", "0.50928090", "0.02552055", 422 | "0.85999075", "0.26692089", "0.01402799", "0.67550392", "0.48305605", 423 | "0.74608351", "0.63408891", "0.58904230", "0.44337996", "0.42174728", 424 | "0.74041679", "0.72719148", "0.19801992", "0.66263633", "0.10381594", 425 | "0.32818760", "0.68369661", "0.56076212", "0.68681921", "0.91616269", 426 | "0.39836106", "0.39685027", "0.97507945", "0.91010563", "0.27447360", 427 | "0.95538357", "0.76758522", "0.60091060", "0.37734461", "0.82948248", 428 | "0.06598078", "0.50147615", "0.08417763", "0.18910044", "0.51661735", 429 | "0.55011011", "0.64888175", "0.82986845", "0.15126656", "0.92649390", 430 | "0.25494941", "0.73275293", "0.94184393", "0.84755226", "0.45921936", 431 | "0.72934054", "0.43722403", "0.34305596", "0.10827860", "0.29026676", 432 | "0.01935431", "0.46668573", "0.83247509", "0.26349603", "0.01938542", 433 | "0.43222250", "0.18109983", "0.29337450", "0.16721917", "0.94751650", 434 | "0.67795254", "0.56666228", "0.20699452", "0.23247262", "0.19138610", 435 | "0.73495506", "0.85893600", "0.83411526", "0.93689655", "0.91804752", 436 | "0.99352333", "0.03207550", "0.28386071", "0.48029543", "0.18736013", 437 | "0.31736452", "0.72542230", "0.57530912", "0.04229918", "0.84798296", 438 | "0.21886935", "0.98655615", "0.52243102", "0.22611020", "0.42975741", 439 | "0.21726739", "0.10912048", "0.96684473", "0.01092456", "0.12461901", 440 | "0.57989070", "0.39848707", "0.06330277", "0.62826828", "0.01159081", 441 | "0.23157320", "0.64690912", "0.44876902", "0.04463930", "0.18933780", 442 | "0.21284518", "0.61363480", "0.67144845", "0.38625586", "0.75719122", 443 | "0.40361050", "0.26708873", "0.54534727", "0.90174015", "0.58654140", 444 | "0.44885346", "0.35505544", "0.65317830", "0.26074572", "0.39472912", 445 | "0.54366914", "0.75020660", "0.76113614", "0.24595582", "0.03941247", 446 | "0.60356153", "0.23615721", "0.01603475", "0.72432457", "0.39837424", 447 | "0.04195329", "0.81561058", "0.34208440", "0.00513953", "0.92826234", 448 | "0.11410393", "0.86692030", "0.25238726", "0.98258626", "0.53353856", 449 | "0.72269001", "0.71850984", "0.66829681", "0.03540769", "0.01676450", 450 | "0.23557835", "0.78758497", "0.85969589", "0.14673207", "0.28013860", 451 | "0.17796942", "0.69924087", "0.44663597", "0.62112513", "0.44079883", 452 | "0.48995231", "0.18411497", "0.18440877", "0.74016388", "0.28845694", 453 | "0.22969080", "0.76851164", "0.15551473", "0.28980810", "0.40906710", 454 | "0.47619039", "0.72611392", "0.55802939", "0.69365597", "0.85736313", 455 | "0.83343150", "0.21324760", "0.45327806", "0.33053855", "0.98198279", 456 | "0.53279389", "0.76877035", "0.20548656", "0.37065042", "0.59026910", 457 | "0.67418036", "0.23585843", "0.98156397", "0.27849804", "0.56198954", 458 | "0.68752287", "0.30073445", "0.69348664", "0.72515585", "0.40629047", 459 | "0.09320027", "0.24334978", "0.91407662", "0.97226538", "0.33904970", 460 | "0.01717092", "0.60155725", "0.03001652", "0.50979706", "0.80531036", 461 | "0.17450719", "0.84984399", "0.00498130", "0.51636405", "0.14080868", 462 | "0.62289701", "0.07853030", "0.70567541", "0.79844050", "0.63766566", 463 | "0.03559031", "0.40994535", "0.08423996", "0.00389626", "0.50608347", 464 | "0.19622681", "0.90537903", "0.75458034", "0.75102094", "0.81491673", 465 | "0.92925931", "0.38074332", "0.54817053", "0.72593246", "0.02146791", 466 | "0.57990460", "0.87921074", "0.59913886", "0.66726893", "0.24269154", 467 | "0.73344575", "0.71826052", "0.92313935", "0.05212996", "0.93771536", 468 | "0.69489385", "0.57581887", "0.48106155", "0.06808800", "0.33633940", 469 | "0.69142320", "0.46566781", "0.70654143", "0.16541368", "0.76257631", 470 | "0.82777900", "0.62958327", "0.34757935", "0.10891487", "0.79912728", 471 | "0.01156543", "0.23111261", "0.58535640", "0.87461956", "0.21723454", 472 | "0.80409615", "0.33169686", "0.72800785", "0.31218099", "0.13729737", 473 | "0.41637635", "0.01234597", "0.58313811", "0.66746028", "0.05105595", 474 | "0.14930937", "0.56044864", "0.76196851", "0.98800104", "0.37075949", 475 | "0.88740864", "0.40697115", "0.96598278", "0.86013661", "0.85386784", 476 | "0.23986516", "0.39027464", "0.59593927", "0.00161530", "0.31768197", 477 | "0.65702729", "0.66461914", "0.62937471", "0.92120758", "0.87578958", 478 | "0.37539860", "0.59182615", "0.12092214", "0.55130437", "0.86365117", 479 | "0.38725162", "0.28757657", "0.42803199", "0.39014405", "0.50253853", 480 | "0.85306128", "0.92018995", "0.71421618", "0.54236780", "0.96221157", 481 | "0.22956898", "0.96519876", "0.06694102", "0.11915854", "0.01354308", 482 | "0.24720070", "0.71671739", "0.00604305", "0.65012352", "0.71151390", 483 | "0.46616159", "0.99228224", "0.20684576", "0.62941006", "0.84535326", 484 | "0.30678993", "0.55264568", "0.50094784", "0.39409122", "0.15479416", 485 | "0.36536318", "0.51925656", "0.65567178", "0.67255519", "0.55089659", 486 | "0.42194295", "0.27172413", "0.79540954", "0.71594806", "0.88372598", 487 | "0.29179452", "0.66411306", "0.57064687", "0.42494633", "0.73389255", 488 | "0.12097313", "0.53338622", "0.38493233", "0.79348021", "0.01851341", 489 | "0.58594454", "0.88396240", "0.04410730", "0.67419924", "0.62770011", 490 | "0.64644200", "0.40335135", "0.17952644", "0.55564678", "0.56643922", 491 | "0.37715015", "0.87092180", "0.56726159", "0.34011210", "0.13661819", 492 | "0.11474177", "0.93930097", "0.48549077", "0.28484289", "0.13374371", 493 | "0.40966056", "0.73662873", "0.37355323", "0.65216092", "0.27372469", 494 | "0.56032082", "0.14882684", "0.95462890", "0.17090266", "0.92374766", 495 | "0.98368259", "0.68448367", "0.02872548", "0.68598279", "0.04601084", 496 | "0.17170501", "0.08906644", "0.23730372", "0.02929037", "0.38566261", 497 | "0.68957569", "0.53021050", "0.44200157", "0.32085701", "0.72520053", 498 | "0.17454174", "0.19676599", "0.88243877", "0.87030228", "0.15124486", 499 | "0.78670160", "0.51731632", "0.56674531", "0.20910664", "0.84962640", 500 | "0.05220467", "0.91783159", "0.19138968", "0.68126378", "0.79574471", 501 | "0.14910848", "0.28030331", "0.98067264", "0.31263980", "0.67448964", 502 | "0.69266650", "0.40033551", "0.22789781", "0.78317066", "0.55815261", 503 | "0.11247054", "0.47337901", "0.46310033", "0.53192452", "0.56164078", 504 | "0.41750378", "0.43880622", "0.69739327", "0.11092778", "0.18333765", 505 | "0.67222441", "0.12789170", "0.88316806", "0.37891271", "0.14935268", 506 | "0.64522185", "0.93902079", "0.62481092", "0.21794927", "0.71535266", 507 | "0.62169579", "0.65147153", "0.01411645", "0.96413465", "0.01021578", 508 | "0.50605180", "0.51595053", "0.03308040", "0.01497870", "0.07809658", 509 | "0.35743383", "0.58079701", "0.11785557", "0.89568677", "0.38793964", 510 | "0.37117709", "0.13994133", "0.11032813", "0.99998594", "0.06695042", 511 | "0.79774786", "0.11093584", "0.23879095", "0.85918615", "0.16109636", 512 | "0.63479696", "0.75023359", "0.29061187", "0.53764772", "0.30652318", 513 | "0.51387302", "0.81620973", "0.82433610", "0.18302488", "0.79048957", 514 | "0.07598187", "0.27887732", "0.37061042", "0.36441016", "0.93736882", 515 | "0.77480946", "0.02269132", "0.40309874", "0.16427650", "0.13969296", 516 | "0.57605029", "0.00242426", "0.56626691", "0.84390990", "0.87455806", 517 | "0.12321023", "0.87561663", "0.60431578", "0.35880839", "0.50426282", 518 | "0.50697689", "0.06631164", "0.14976092", "0.89356018", "0.91473662", 519 | "0.04235237", "0.50073724", "0.75969690", "0.91743994", "0.79352335", 520 | "0.58078351", "0.91819984", "0.53520520", "0.18267367", "0.05608828", 521 | "0.68315721", "0.27264599", "0.41245634", "0.69706222", "0.69666203", 522 | "0.08967342", "0.64081905", "0.22576796", "0.69315628", "0.53981640", 523 | "0.76059129", "0.56712344", "0.94318621", "0.44081094", "0.31699284", 524 | "0.29477911", "0.80069824", "0.28366921", "0.96718081", "0.85345644", 525 | "0.11681215", "0.47600710", "0.33448255", "0.31217271", "0.35469241", 526 | "0.59511650", "0.49583692", "0.48922303", "0.20215259", "0.60159380", 527 | "0.17882055", "0.77601258", "0.71020391", "0.41833503", "0.71522856", 528 | "0.87534517", "0.43703394", "0.43056077", "0.64828071", "0.43069441", 529 | "0.39356849", "0.32063367", "0.92788963", "0.16878266", "0.56762591", 530 | "0.56042446", "0.84958464", "0.79408949", "0.08220340", "0.13922856", 531 | "0.82529019", "0.27134959", "0.00278080", "0.66192389", "0.01782933", 532 | "0.95404763", "0.50787645", "0.85320521", "0.83690362", "0.83771227", 533 | "0.46268665", "0.31716742", "0.01716647", "0.68264674", "0.01789888", 534 | "0.30446846", "0.14942271", "0.26982182", "0.74933947", "0.50394161", 535 | "0.78444542", "0.40009256", "0.40333422", "0.16627342", "0.01898760", 536 | "0.04221829", "0.77960213", "0.66230976", "0.56015996", "0.49535426", 537 | "0.38536259", "0.40406773", "0.99930568", "0.00857945", "0.16158390", 538 | "0.64805163", "0.20237524", "0.59106326", "0.76968277", "0.96887042", 539 | "0.29264851", "0.97373775", "0.16767633", "0.33014482", "0.27426548", 540 | "0.10947014", "0.75920652", "0.37757457", "0.13125207", "0.00826451", 541 | "0.96684342", "0.69362226", "0.22763554", "0.20717541", "0.42112268", 542 | "0.22803038", "0.33481806", "0.14968742", "0.71598558", "0.55126711", 543 | "0.64518015", "0.65170197", "0.89103003", "0.72728361", "0.24485454", 544 | "0.09410780", "0.79818029", "0.54212409", "0.17790462", "0.64442619", 545 | "0.62193511", "0.51193256", "0.02848781", "0.05719604", "0.45795152", 546 | "0.03219332", "0.28310254", "0.85746127", "0.64890240", "0.20658356", 547 | "0.50946422", "0.80432490", "0.08354468", "0.09222723", "0.67455943", 548 | "0.44638771", "0.76366629", "0.99677267", "0.89311242", "0.11627279", 549 | "0.09181302", "0.44767077", "0.16448724", "0.26005539", "0.28670391", 550 | "0.52465703", "0.43598116", "0.41869096", "0.98043420", "0.01497272", 551 | "0.51791571", "0.61825308", "0.85503436", "0.63025655", "0.02719292", 552 | "0.09865668", "0.30321729", "0.56998039", "0.14946350", "0.64823918", 553 | "0.19931639", "0.14623555", "0.54169913", "0.68944135", "0.73551005", 554 | "0.46743658", "0.04109096", "0.26625801", "0.09537298", "0.98207890", 555 | "0.58109721", "0.70793680", "0.84379365", "0.42774726", "0.12653597", 556 | "0.08566633", "0.53366781", "0.33960092", "0.11036831", "0.84464510", 557 | "0.16493476", "0.92493443", "0.87640673", "0.52727644", "0.57181349", 558 | "0.65071340", "0.00978637", "0.31700693", "0.69148222", "0.85063311", 559 | "0.06781819", "0.30794534", "0.65541667", "0.16400484", "0.06886223", 560 | "0.96227205", "0.09633060", "0.34513153", "0.31013900", "0.78165882", 561 | "0.39583699", "0.86327936", "0.69269199", "0.11016575", "0.67358419", 562 | "0.81775427", "0.50052824", "0.30068582", "0.16606837", "0.62243724", 563 | "0.47863741", "0.68796498", "0.31526949", "0.41180883", "0.23022147", 564 | "0.82342139", "0.83003381", "0.53571829", "0.41081533", "0.48600142", 565 | } 566 | 567 | func Test_MT19937(t *testing.T) { 568 | mt := New() 569 | mt.SeedFromSlice([]uint64{0x12345, 0x23456, 0x34567, 0x45678}) 570 | 571 | for i, want := range expectedInt { 572 | have := mt.Uint64() 573 | if have != want { 574 | t.Errorf("wrong output %d: %d != %d", i, have, want) 575 | } 576 | } 577 | 578 | for i, want := range expectedReal { 579 | have := fmt.Sprintf("%10.8f", mt.Real2()) 580 | if have != want { 581 | t.Errorf("wrong output %d: %d != %s", i, have, want) 582 | } 583 | } 584 | } 585 | 586 | func Benchmark_MT19937_Uint64(b *testing.B) { 587 | mt := New() 588 | b.SetBytes(8) 589 | b.ResetTimer() 590 | for i := 0; i < b.N; i++ { 591 | mt.Uint64() 592 | } 593 | } 594 | 595 | func Benchmark_MT19937_Int63(b *testing.B) { 596 | mt := New() 597 | b.SetBytes(8) 598 | b.ResetTimer() 599 | for i := 0; i < b.N; i++ { 600 | mt.Int63() 601 | } 602 | } 603 | 604 | func Benchmark_Builtin_Int63(b *testing.B) { 605 | rng := rand.NewSource(1) 606 | b.SetBytes(8) 607 | b.ResetTimer() 608 | for i := 0; i < b.N; i++ { 609 | rng.Int63() 610 | } 611 | } 612 | 613 | // Compile time test: MT19937 implements the math.Source interface. 614 | var _ rand.Source = &MT19937{} 615 | -------------------------------------------------------------------------------- /rc4/README.md: -------------------------------------------------------------------------------- 1 | RC4加密算法应用代码集 2 | =================== 3 | 4 | 这个目录下的代码用于测试DH64密钥交换 + RC4加密算法的跨语言兼容性。 5 | 6 | 实验使用一个Go语言实现的服务端和不同语言实现的客户端来测试兼容性。 7 | 8 | 客户端连接到服务端后,双方会互发DH64密钥交换用的公钥,双方在得到对方的公钥后即可计算出通讯密钥。 9 | 10 | 客户端使用通讯密钥进行RC4加密,连续发随机大小和随机内容的消息包给服务端。 11 | 12 | 服务端使用通讯密钥进行RC4解密,收到消息包后将解密出来的明文消息包回传给客户端。 13 | 14 | 客户端收到明文回传消息包后确认是否与加密前的消息包一致,以确认加解密算法是否正确。 -------------------------------------------------------------------------------- /rc4/csharp/rc4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Funny.Crypto 5 | { 6 | public class RC4Cipher 7 | { 8 | private uint[] s = new uint[256]; 9 | private byte i, j; 10 | 11 | public RC4Cipher(byte[] key) { 12 | int k = key.Length; 13 | if (k < 1 || k > 256) { 14 | throw new RC4KeySizeException(k); 15 | } 16 | 17 | for (uint i = 0; i < 256; i++) { 18 | s[i] = i; 19 | } 20 | 21 | byte j = 0; 22 | uint t = 0; 23 | for (int i = 0; i < 256; i++) { 24 | j = (byte)(j + s[i] + key[i % k]); 25 | t = s[i]; 26 | s[i] = s[j]; 27 | s[j] = t; 28 | } 29 | } 30 | 31 | public void XORKeyStream(byte[] dst, int dstOffset, byte[] src, int srcOffset, int count) { 32 | if (count == 0) 33 | return; 34 | 35 | byte i = this.i; 36 | byte j = this.j; 37 | uint t = 0; 38 | for (int k = 0; k < count; k ++) { 39 | i += 1; 40 | j = (byte)(s[i] + j); 41 | t = s[i]; 42 | s[i] = s[j]; 43 | s[j] = t; 44 | dst[k + dstOffset] = (byte)(src[k + srcOffset] ^ (byte)(s[(byte)(s[i] + s[j])])); 45 | } 46 | this.i = i; 47 | this.j = j; 48 | } 49 | } 50 | 51 | public class RC4Stream : Stream 52 | { 53 | private Stream stream; 54 | private RC4Cipher cipher; 55 | 56 | public RC4Stream(Stream stream, byte[] key) { 57 | this.stream = stream; 58 | this.cipher = new RC4Cipher(key); 59 | } 60 | 61 | public override int Read(byte[] buffer, int offset, int count) { 62 | count = stream.Read(buffer, offset, count); 63 | cipher.XORKeyStream(buffer, offset, buffer, offset, count); 64 | return count; 65 | } 66 | 67 | public override void Write(byte[] buffer, int offset, int count) { 68 | byte[] dst = new byte[count]; 69 | cipher.XORKeyStream(dst, 0, buffer, offset, count); 70 | stream.Write(dst, 0, count); 71 | } 72 | 73 | public override bool CanRead { 74 | get { return stream.CanRead; } 75 | } 76 | 77 | public override bool CanSeek { 78 | get { return stream.CanSeek; } 79 | } 80 | 81 | public override bool CanWrite { 82 | get { return stream.CanWrite; } 83 | } 84 | 85 | public override long Length { 86 | get { return stream.Length; } 87 | } 88 | 89 | public override long Position { 90 | get { return stream.Position; } 91 | set { stream.Position = value; } 92 | } 93 | 94 | public override long Seek(long offset, SeekOrigin origin) { 95 | return stream.Seek(offset, origin); 96 | } 97 | 98 | public override void SetLength(long length) { 99 | stream.SetLength(length); 100 | } 101 | 102 | public override void Flush() { 103 | stream.Flush(); 104 | } 105 | } 106 | 107 | public class RC4KeySizeException : Exception 108 | { 109 | private int size; 110 | 111 | public RC4KeySizeException(int size) { 112 | this.size = size; 113 | } 114 | 115 | public override string Message { 116 | get { return "RC4Stream: invalid key size " + size; } 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /rc4/csharp/rc4_echo_client.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net.Sockets; 4 | using Funny.Crypto; 5 | 6 | // mcs rc4_echo_client.cs rc4.cs ../../dh64/csharp/dh64.cs 7 | class MainClass 8 | { 9 | private static DH64 dh64 = new DH64(); 10 | private static Random random = new Random(); 11 | 12 | public static void Main(string[] args) { 13 | TcpClient conn = new TcpClient("127.0.0.1", 10010); 14 | Console.WriteLine("client connect"); 15 | 16 | Stream stream = conn.GetStream(); 17 | BinaryReader reader = new BinaryReader(stream); 18 | BinaryWriter writer = ConnInit(reader); 19 | 20 | byte[] buffer = new byte[1024]; 21 | for (;;) { 22 | int length = WriteRandomBytes(writer, buffer); 23 | uint n = reader.ReadUInt32(); 24 | byte[] recv = reader.ReadBytes((int)n); 25 | if (!ByteArrayEquals(buffer, recv, length)) { 26 | Console.WriteLine("send != recv"); 27 | Console.WriteLine("send: {0}", BitConverter.ToString(buffer, length)); 28 | Console.WriteLine("recv: {0}", BitConverter.ToString(recv)); 29 | return; 30 | } 31 | } 32 | } 33 | 34 | // Do DH64 key exchange and return a RC4 writer 35 | private static BinaryWriter ConnInit(BinaryReader r) { 36 | ulong privateKey; 37 | ulong publicKey; 38 | dh64.KeyPair(out privateKey, out publicKey); 39 | Console.WriteLine("client public key: {0}", publicKey); 40 | 41 | new BinaryWriter(r.BaseStream).Write(publicKey); 42 | ulong srvPublicKey = r.ReadUInt64(); 43 | Console.WriteLine("server public key: {0}", srvPublicKey); 44 | 45 | ulong secret = dh64.Secret(privateKey, srvPublicKey); 46 | Console.WriteLine("secret: {0}", secret); 47 | 48 | byte[] key; 49 | using (MemoryStream ms = new MemoryStream()) { 50 | new BinaryWriter(ms).Write(secret); 51 | key = ms.ToArray(); 52 | } 53 | Console.WriteLine("key: {0}", BitConverter.ToString(key).Replace("-", "").ToLower()); 54 | 55 | return new BinaryWriter( 56 | new RC4Stream(r.BaseStream, key) 57 | ); 58 | } 59 | 60 | private static int WriteRandomBytes(BinaryWriter w, byte[] buffer) { 61 | int length = random.Next(buffer.Length); 62 | for (int i = 0; i < length; i ++) { 63 | buffer[i] = (byte)random.Next(256); 64 | } 65 | w.Write((uint)length); 66 | w.Write(buffer, 0, length); 67 | return length; 68 | } 69 | 70 | private static bool ByteArrayEquals(byte[] a1, byte[] a2, int length) { 71 | if (a2.Length != length) 72 | return false; 73 | for (int i=0; i time.Second*2 { 64 | lastPrintTime = time.Now() 65 | log.Print("server: ", recvPacketCount, sendPacketCount) 66 | } 67 | } 68 | }() 69 | } 70 | } 71 | 72 | // Do DH64 key exchange and return a RC4 reader. 73 | func conn_init(conn net.Conn) (*binary.Writer, *binary.Reader, error) { 74 | var ( 75 | writer = binary.NewWriter(conn) 76 | reader = binary.NewReader(conn) 77 | ) 78 | 79 | rand.Seed(time.Now().UnixNano()) 80 | 81 | privateKey, publicKey := dh64.KeyPair() 82 | log.Print("server public key: ", publicKey) 83 | 84 | writer.WriteUint64LE(publicKey) 85 | if writer.Error() != nil { 86 | return nil, nil, writer.Error() 87 | } 88 | clientPublicKey := reader.ReadUint64LE() 89 | if reader.Error() != nil { 90 | return nil, nil, reader.Error() 91 | } 92 | log.Print("client public key: ", clientPublicKey) 93 | 94 | secert := dh64.Secret(privateKey, clientPublicKey) 95 | log.Print("secert: ", secert) 96 | 97 | key := make([]byte, 8) 98 | binary.PutUint64LE(key, secert) 99 | rc4stream, err := rc4.NewCipher(key) 100 | if err != nil { 101 | return nil, nil, err 102 | } 103 | log.Print("key: ", hex.EncodeToString(key)) 104 | 105 | reader = binary.NewReader(cipher.StreamReader{ 106 | R: conn, 107 | S: rc4stream, 108 | }) 109 | return writer, reader, nil 110 | } 111 | --------------------------------------------------------------------------------