How to evaluate eagerly a sequence coming from grep in Raku? - lazy-evaluation

I don't understand how laziness / eagerness works in Raku. More precisely how to force eagerness.
I get that Infinite List are lazy. What I don't understand is that some List that have an end are lazy, and why the eager method doesn't work in my case.
I have this example
raku -e 'say (1..*).grep({ .is-prime })[^100]'
which works fine when I want to obtain the first 100 elements. But when I want more, say 200, I can't manage to get these 200 elements.
I know I can iterate over them with a for loop. Like this
raku -e 'for (1..*).grep({ .is-prime })[0..200] { .say }'
raku -e '.say for (1..*).grep({ .is-prime })[0..200]'
What I want to do is get the elements with the same functional syntax as above. (the one without the for loop)
I tried those but none works
raku -e 'say (1..*).grep({ .is-prime })[^200].eager'
raku -e 'say (1..*).grep({ .is-prime })[eager ^200]'
raku -e 'say eager (1..*).grep({ .is-prime })[^200]'
raku -e 'say (1..*).grep({ .is-prime })[0..200].eager'
raku -e 'say (1..*).grep({ .is-prime })[eager 0..200]'
raku -e 'say eager (1..*).grep({ .is-prime })[0..200]'
Can someone please tell me how to do it ?

This has nothing todo with grep or eager, but everything to do with the .gist method that creates a string representation of an object, and which is called by say. Since gists are intended for human consumption, they are intentionally not always complete: of Iterables, .gist only shows the first 100 elements:
my #a = ^100;
say #a;
# [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99]
my #a = ^101;
say #a;
# [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...]
There are various solutions: you could use put instead of say, which will call the Str method, which generally will show all elements:
my #a = ^101;
put #a;
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Or if you want to get a technically correct representation, you can call the .raku method:
my #a = ^101;
say #a.raku;
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
So, to get back to your examples:
put (1..*).grep({ .is-prime })[^200];
# 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223
say (1..*).grep({ .is-prime })[^200].raku;
# (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223)
Fortunately, there's a shorter way to get the .raku representation: dd
dd (1..*).grep({ .is-prime })[^200];
# (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223)
dd calls .raku on whatever it is given, and also collects some extra debugging information when possible, and prints that on STDERR.

Related

Hadoop standby UI not coming up after enabling SSL. no cipher suites in common

I have enabled SSL in hadoop cluster in ambari using signed certs via custom self-signed CA. However, only Namenode1 UI is opening and Namenode2 UI is giving ERR_SSL_VERSION_OR_CIPHER_MISMATCH. All signed certs including CA cert are in java truststore and custom truststore. In backend, cluster is up and running Active/Slave mode as it should be. Pasted debug logs for server & client ssl handshake.
%% No cached client session
update handshake state: client_hello[1]
upcoming handshake states: server_hello[2]
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1552146602 bytes = { 124, 246, 85, 32, 231, 117, 102, 26, 129, 194, 161, 10, 142, 155, 11, 83, 45, 193, 13, 189, 43, 178, 57, 21, 53, 202, 219, 200 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA224withECDSA, SHA224withRSA, SHA224withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
Extension extended_master_secret
Extension server_name, server_name: [type=host_name (0), value=example-infra-01.example.com]
***
main, WRITE: TLSv1.2 Handshake, length = 232
main, READ: TLSv1.2 Handshake, length = 1461
check handshake state: server_hello[2]
*** ServerHello, TLSv1.2
RandomCookie: GMT: 1552146602 bytes = { 74, 111, 68, 189, 88, 130, 151, 116, 37, 202, 171, 111, 66, 248, 239, 41, 250, 142, 55, 7, 207, 189, 203, 250, 210, 210, 141, 80 }
Session ID: {93, 132, 225, 170, 221, 77, 24, 110, 248, 135, 94, 71, 89, 216, 117, 97, 101, 98, 53, 53, 19, 30, 141, 221, 62, 185, 153, 241, 122, 113, 23, 100}
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Compression Method: 0
Extension renegotiation_info, renegotiated_connection: <empty>
Extension server_name, server_name:
Extension extended_master_secret
***
%% Initialized: [Session-7, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384]
** TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
update handshake state: server_hello[2]
upcoming handshake states: server certificate[11]
upcoming handshake states: server_key_exchange[12](optional)
upcoming handshake states: certificate_request[13](optional)
upcoming handshake states: server_hello_done[14]
upcoming handshake states: client certificate[11](optional)
upcoming handshake states: client_key_exchange[16]
upcoming handshake states: certificate_verify[15](optional)
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
check handshake state: certificate[11]
update handshake state: certificate[11]
upcoming handshake states: server_key_exchange[12](optional)
upcoming handshake states: certificate_request[13](optional)
upcoming handshake states: server_hello_done[14]
upcoming handshake states: client certificate[11](optional)
upcoming handshake states: client_key_exchange[16]
upcoming handshake states: certificate_verify[15](optional)
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
*** Certificate chain
chain [0] = [
[
Version: V3
Subject: EMAILADDRESS=exampletest02#example.com, CN=example-infra-01.example.com, OU=dev, O=org, L=current, ST=state, C=country
Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11
Key: Sun RSA public key, 2048 bits
modulus: 21841755142500677173038686755031873041366701846670510917687245038534981997174536899121267104976251234487931691682356456587057979146131226006486802945627458953213345485002320762746572550140153263127388890940484242628083923909940555188294345156730990162012315907130788552918940050956069183125819873814807318195323024331782362924669648387137160317840086368280513586813886958200363786656575039759673832758101555834192465439708239536183449763070916218201916947796469040269718952095684909120070890691280563367820197999332144131568815041448905148594619506642918085699503567938203770656599824571574354719182434767493343531767
public exponent: 65537
Validity: [From: Fri Sep 20 11:20:44 UTC 2019,
To: Mon Sep 17 11:20:44 UTC 2029]
Issuer: EMAILADDRESS=exampletest02#example.com, CN=exampletest02CA, OU=dev, O=org, L=current, ST=state, C=country
SerialNumber: [ f353]
Certificate Extensions: 1
[1]: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
DNSName: example-infra-01.example.com
]
]
Algorithm: [SHA256withRSA]
Signature:
0000: 54 F3 7D 47 26 59 C8 1A B8 35 04 45 88 B8 64 ED T..G&Y...5.E..d.
0010: 9B BD CB 80 D0 34 3D B5 B2 FF A7 71 A6 12 4A 26 .....4=....q..J&
0020: DE EC 2B A3 7D 10 E4 5E 94 EE 01 E0 9A 54 F2 EA ..+....^.....T..
0030: EC 3C 1B B6 5B 90 73 11 3B 3C DC FB 85 FF CE 8E .<..[.s.;<......
0040: 03 41 6C CE 81 89 25 0C 7C EF 03 AE 31 2F 8D CD .Al...%.....1/..
0050: AB C2 81 6C DB 7E CA 07 00 0F B6 01 E4 67 EA A0 ...l.........g..
0060: 84 3B 94 6A 53 5B 47 70 0B 58 BE 2D D4 2E D5 F8 .;.jS[Gp.X.-....
0070: 00 7E D2 1D C4 C1 D3 0F 42 5D 83 0E 8A DB A9 89 ........B]......
0080: 82 5A D8 5E D5 C8 B6 CE 51 E8 36 EC 23 1B 13 8C .Z.^....Q.6.#...
0090: 2D 93 B3 1B F4 37 A1 B5 BA 56 B7 00 51 96 CE CB -....7...V..Q...
00A0: BB 53 8C F8 60 0E 90 0B A7 1C 58 5F 54 D9 BE B7 .S..`.....X_T...
00B0: 61 06 8A 67 25 0C D5 68 15 14 34 BB 69 F2 96 66 a..g%..h..4.i..f
00C0: CE DC 57 3A 90 E5 22 1D 52 8E 89 68 AC 3D C3 3B ..W:..".R..h.=.;
00D0: 19 CA 59 C6 03 6C 16 38 4E 94 25 49 53 49 6C B2 ..Y..l.8N.%ISIl.
00E0: CE 13 13 82 C5 84 E5 5E 1B 9B 94 54 23 B8 29 1E .......^...T#.).
00F0: 17 E0 4A 5F BF 58 DE 9E 2A 25 9B C2 32 EA E5 F6 ..J_.X..*%..2...
]
***
Found trusted certificate:
[
[
Version: V3
Subject: EMAILADDRESS=exampletest02#example.com, CN=example-infra-01.example.com, OU=dev, O=org, L=current, ST=state, C=country
Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11
Key: Sun RSA public key, 2048 bits
modulus: 21841755142500677173038686755031873041366701846670510917687245038534981997174536899121267104976251234487931691682356456587057979146131226006486802945627458953213345485002320762746572550140153263127388890940484242628083923909940555188294345156730990162012315907130788552918940050956069183125819873814807318195323024331782362924669648387137160317840086368280513586813886958200363786656575039759673832758101555834192465439708239536183449763070916218201916947796469040269718952095684909120070890691280563367820197999332144131568815041448905148594619506642918085699503567938203770656599824571574354719182434767493343531767
public exponent: 65537
Validity: [From: Fri Sep 20 11:20:44 UTC 2019,
To: Mon Sep 17 11:20:44 UTC 2029]
Issuer: EMAILADDRESS=exampletest02#example.com, CN=exampletest02CA, OU=dev, O=org, L=current, ST=state, C=country
SerialNumber: [ f353]
Certificate Extensions: 1
[1]: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
DNSName: example-infra-01.example.com
]
]
Algorithm: [SHA256withRSA]
Signature:
0000: 54 F3 7D 47 26 59 C8 1A B8 35 04 45 88 B8 64 ED T..G&Y...5.E..d.
0010: 9B BD CB 80 D0 34 3D B5 B2 FF A7 71 A6 12 4A 26 .....4=....q..J&
0020: DE EC 2B A3 7D 10 E4 5E 94 EE 01 E0 9A 54 F2 EA ..+....^.....T..
0030: EC 3C 1B B6 5B 90 73 11 3B 3C DC FB 85 FF CE 8E .<..[.s.;<......
0040: 03 41 6C CE 81 89 25 0C 7C EF 03 AE 31 2F 8D CD .Al...%.....1/..
0050: AB C2 81 6C DB 7E CA 07 00 0F B6 01 E4 67 EA A0 ...l.........g..
0060: 84 3B 94 6A 53 5B 47 70 0B 58 BE 2D D4 2E D5 F8 .;.jS[Gp.X.-....
0070: 00 7E D2 1D C4 C1 D3 0F 42 5D 83 0E 8A DB A9 89 ........B]......
0080: 82 5A D8 5E D5 C8 B6 CE 51 E8 36 EC 23 1B 13 8C .Z.^....Q.6.#...
0090: 2D 93 B3 1B F4 37 A1 B5 BA 56 B7 00 51 96 CE CB -....7...V..Q...
00A0: BB 53 8C F8 60 0E 90 0B A7 1C 58 5F 54 D9 BE B7 .S..`.....X_T...
00B0: 61 06 8A 67 25 0C D5 68 15 14 34 BB 69 F2 96 66 a..g%..h..4.i..f
00C0: CE DC 57 3A 90 E5 22 1D 52 8E 89 68 AC 3D C3 3B ..W:..".R..h.=.;
00D0: 19 CA 59 C6 03 6C 16 38 4E 94 25 49 53 49 6C B2 ..Y..l.8N.%ISIl.
00E0: CE 13 13 82 C5 84 E5 5E 1B 9B 94 54 23 B8 29 1E .......^...T#.).
00F0: 17 E0 4A 5F BF 58 DE 9E 2A 25 9B C2 32 EA E5 F6 ..J_.X..*%..2...
]
check handshake state: server_key_exchange[12]
update handshake state: server_key_exchange[12]
upcoming handshake states: certificate_request[13](optional)
upcoming handshake states: server_hello_done[14]
upcoming handshake states: client certificate[11](optional)
upcoming handshake states: client_key_exchange[16]
upcoming handshake states: certificate_verify[15](optional)
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
*** ECDH ServerKeyExchange
Signature Algorithm SHA512withRSA
Server key: Sun EC public key, 256 bits
public x coord: 71243459788679529452333968749910729075781137069187014570295198815671440442567
public y coord: 113361508572920438429337576097115462276383236410260704000629230880259446655931
parameters: secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)
check handshake state: server_hello_done[14]
update handshake state: server_hello_done[14]
upcoming handshake states: client certificate[11](optional)
upcoming handshake states: client_key_exchange[16]
upcoming handshake states: certificate_verify[15](optional)
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
*** ServerHelloDone
*** ECDHClientKeyExchange
ECDH Public value: { 4, 152, 139, 246, 59, 71, 138, 250, 25, 160, 51, 106, 181, 172, 76, 157, 91, 105, 32, 165, 230, 140, 77, 233, 215, 0, 196, 240, 108, 155, 117, 232, 15, 162, 215, 135, 203, 87, 222, 29, 97, 172, 72, 136, 204, 71, 25, 247, 149, 241, 148, 109, 231, 95, 118, 19, 176, 121, 145, 52, 44, 166, 16, 187, 155 }
update handshake state: client_key_exchange[16]
upcoming handshake states: certificate_verify[15](optional)
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
main, WRITE: TLSv1.2 Handshake, length = 70
SESSION KEYGEN:
PreMaster Secret:
0000: 7F DA 03 00 E7 C3 71 FA 17 21 E6 F3 A0 3D E2 36 ......q..!...=.6
0010: BD 95 F2 6F 99 72 77 99 8F 80 F7 38 44 8D 82 F6 ...o.rw....8D...
CONNECTION KEYGEN:
Client Nonce:
0000: 5D 84 E1 AA 7C F6 55 20 E7 75 66 1A 81 C2 A1 0A ].....U .uf.....
0010: 8E 9B 0B 53 2D C1 0D BD 2B B2 39 15 35 CA DB C8 ...S-...+.9.5...
Server Nonce:
0000: 5D 84 E1 AA 4A 6F 44 BD 58 82 97 74 25 CA AB 6F ]...JoD.X..t%..o
0010: 42 F8 EF 29 FA 8E 37 07 CF BD CB FA D2 D2 8D 50 B..)..7........P
Master Secret:
0000: 0B E0 95 54 2E EE 98 F8 10 16 1B 09 D1 B5 17 8E ...T............
0010: B7 79 CC 19 14 CF 26 FF B6 78 BC CA FC 0D F9 03 .y....&..x......
0020: 8F 2F B9 0C 61 13 BD C5 BF 55 80 FE FE 0E FA B1 ./..a....U......
Client MAC write Secret:
0000: 68 B0 DB F5 7C F5 B4 B6 CA 55 1F E3 FC 02 03 8A h........U......
0010: 26 7A FF 5C 43 7D 7C D4 9E 13 4A F1 37 FB 87 BC &z.\C.....J.7...
0020: 8A 2B 0E 02 CC B0 10 59 8D 18 B7 E8 9F D4 1B 57 .+.....Y.......W
Server MAC write Secret:
0000: B5 EE 51 5F 4B FC 2E F6 72 CF 51 8A 9E 77 00 90 ..Q_K...r.Q..w..
0010: D7 73 B4 95 03 99 38 CE B8 13 C5 53 FA 45 7F 90 .s....8....S.E..
0020: 23 B2 9F 47 CB 43 B6 2C 89 1E 33 EB 74 C1 05 70 #..G.C.,..3.t..p
Client write key:
0000: D5 2C 69 E9 C9 45 A2 09 F2 C5 19 8C FE 78 F4 64 .,i..E.......x.d
0010: 38 8E E1 7A D1 4A 23 8F 82 11 31 B5 91 E8 6F D1 8..z.J#...1...o.
Server write key:
0000: 69 24 D3 17 8A 54 8D 14 3A 62 0D 0B AC 05 BA 9E i$...T..:b......
0010: 1B BD C2 79 EF 8F 79 A7 27 A4 65 4F 66 DB E6 33 ...y..y.'.eOf..3
... no IV derived for this protocol
update handshake state: change_cipher_spec
upcoming handshake states: client finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
main, WRITE: TLSv1.2 Change Cipher Spec, length = 1
*** Finished
verify_data: { 128, 248, 254, 214, 242, 88, 203, 66, 123, 158, 131, 38 }
***
update handshake state: finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
main, WRITE: TLSv1.2 Handshake, length = 96
main, READ: TLSv1.2 Change Cipher Spec, length = 1
update handshake state: change_cipher_spec
upcoming handshake states: server finished[20]
main, READ: TLSv1.2 Handshake, length = 96
check handshake state: finished[20]
update handshake state: finished[20]
*** Finished
verify_data: { 7, 205, 135, 154, 166, 68, 152, 172, 238, 87, 23, 223 }
***
%% Cached client session: [Session-7, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384]
main, WRITE: TLSv1.2 Application Data, length = 400
main, READ: TLSv1.2 Application Data, length = 304
main, called close()
main, called closeInternal(true)
main, SEND TLSv1.2 ALERT: warning, description = close_notify
main, WRITE: TLSv1.2 Alert, length = 80
main, called closeSocket(true)
Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
main, setSoTimeout(60000) called
main, the previous server name in SNI (type=host_name (0), value=example-infra-01.example.com) was replaced with (type=host_name (0), value=example-infra-01.example.com)
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 for TLSv1.1
%% Client cached [Session-7, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384]
%% Try resuming [Session-7, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384] from port 38288
update handshake state: client_hello[1]
upcoming handshake states: server_hello[2]
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1552146602 bytes = { 156, 4, 46, 63, 96, 91, 233, 184, 59, 248, 73, 0, 6, 45, 107, 156, 136, 184, 177, 47, 63, 14, 208, 172, 82, 179, 167, 79 }
Session ID: {93, 132, 225, 170, 221, 77, 24, 110, 248, 135, 94, 71, 89, 216, 117, 97, 101, 98, 53, 53, 19, 30, 141, 221, 62, 185, 153, 241, 122, 113, 23, 100}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA224withECDSA, SHA224withRSA, SHA224withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
Extension extended_master_secret
Extension server_name, server_name: [type=host_name (0), value=example-infra-01.example.com]
***
main, WRITE: TLSv1.2 Handshake, length = 264
main, READ: TLSv1.2 Handshake, length = 85
check handshake state: server_hello[2]
*** ServerHello, TLSv1.2
RandomCookie: GMT: 1552146602 bytes = { 54, 37, 146, 192, 105, 253, 113, 196, 34, 251, 28, 19, 242, 223, 145, 202, 72, 194, 181, 147, 86, 35, 253, 145, 193, 227, 29, 180 }
Session ID: {93, 132, 225, 170, 221, 77, 24, 110, 248, 135, 94, 71, 89, 216, 117, 97, 101, 98, 53, 53, 19, 30, 141, 221, 62, 185, 153, 241, 122, 113, 23, 100}
Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Compression Method: 0
Extension renegotiation_info, renegotiated_connection: <empty>
Extension extended_master_secret
***
CONNECTION KEYGEN:
Client Nonce:
0000: 5D 84 E1 AA 9C 04 2E 3F 60 5B E9 B8 3B F8 49 00 ]......?`[..;.I.
0010: 06 2D 6B 9C 88 B8 B1 2F 3F 0E D0 AC 52 B3 A7 4F .-k..../?...R..O
Server Nonce:
0000: 5D 84 E1 AA 36 25 92 C0 69 FD 71 C4 22 FB 1C 13 ]...6%..i.q."...
0010: F2 DF 91 CA 48 C2 B5 93 56 23 FD 91 C1 E3 1D B4 ....H...V#......
Master Secret:
0000: 0B E0 95 54 2E EE 98 F8 10 16 1B 09 D1 B5 17 8E ...T............
0010: B7 79 CC 19 14 CF 26 FF B6 78 BC CA FC 0D F9 03 .y....&..x......
0020: 8F 2F B9 0C 61 13 BD C5 BF 55 80 FE FE 0E FA B1 ./..a....U......
Client MAC write Secret:
0000: E0 19 EA 79 72 6D 05 6B 85 E6 14 1D 97 73 B9 40 ...yrm.k.....s.#
0010: 43 9B 1F 2E A5 B3 67 84 B0 9D 16 C9 E0 EC 0A 68 C.....g........h
0020: EF 31 10 83 19 D1 A3 CA 6A 83 3F AC 31 A2 B6 E5 .1......j.?.1...
Server MAC write Secret:
0000: E0 73 33 C9 08 40 53 30 21 BA 38 F7 BD F6 8D 81 .s3..#S0!.8.....
0010: 27 24 5F 05 78 A8 DC 77 04 30 19 32 06 79 39 54 '$_.x..w.0.2.y9T
0020: A9 AA 46 87 CD C9 12 FD 92 DD B6 0E 9A 36 96 17 ..F..........6..
Client write key:
0000: 4D F3 EF 58 06 82 5B 6E 5B FB 3C 06 D6 BF 31 6D M..X..[n[.<...1m
0010: 8B B2 17 D0 70 A3 12 60 A9 8D E9 EB E3 B6 D5 1C ....p..`........
Server write key:
0000: 31 BD FD 1E 38 51 61 57 E5 F3 47 4D 0C 76 3D 92 1...8QaW..GM.v=.
0010: 74 1F 3C 27 23 7A C7 91 01 B1 27 90 0C 3C EC A6 t.<'#z....'..<..
... no IV derived for this protocol
%% Server resumed [Session-7, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384]
update handshake state: server_hello[2]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
main, READ: TLSv1.2 Change Cipher Spec, length = 1
update handshake state: change_cipher_spec
upcoming handshake states: server finished[20]
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
main, READ: TLSv1.2 Handshake, length = 96
check handshake state: finished[20]
update handshake state: finished[20]
upcoming handshake states: client change_cipher_spec[-1]
upcoming handshake states: client finished[20]
*** Finished
verify_data: { 75, 62, 236, 200, 14, 200, 178, 123, 37, 211, 140, 250 }
***
update handshake state: change_cipher_spec
upcoming handshake states: client finished[20]
main, WRITE: TLSv1.2 Change Cipher Spec, length = 1
*** Finished
verify_data: { 185, 171, 138, 219, 67, 211, 3, 16, 36, 213, 230, 75 }
***
update handshake state: finished[20]
main, WRITE: TLSv1.2 Handshake, length = 96
main, WRITE: TLSv1.2 Application Data, length = 1408
main, READ: TLSv1.2 Application Data, length = 880
main, setSoTimeout(60000) called
main, WRITE: TLSv1.2 Application Data, length = 560
main, READ: TLSv1.2 Application Data, length = 912
Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
qtp2092801316-44, READ: TLSv1 Handshake, length = 211
check handshake state: client_hello[1]
update handshake state: client_hello[1]
upcoming handshake states: server_hello[2]
*** ClientHello, TLSv1.2
RandomCookie: GMT: -1465277827 bytes = { 145, 94, 102, 159, 70, 125, 116, 216, 246, 70, 130, 67, 253, 91, 217, 187, 215, 75, 95, 191, 145, 123, 47, 190, 114, 8, 235, 115 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, Unknown 0xcc:0xa9, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, Unknown 0xcc:0xa8, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, Unknown 0xcc:0xaa, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256, SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_MD5]
Compression Methods: { 0 }
Extension server_name, server_name: [type=host_name (0), value=example-mst-02.example.com]
Extension renegotiation_info, renegotiated_connection: <empty>
Extension elliptic_curves, curve names: {unknown curve 29, secp256r1, secp384r1, secp521r1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA256withECDSA, SHA384withECDSA, SHA512withECDSA, SHA1withECDSA, Unknown (hash:0x8, signature:0x4), Unknown (hash:0x8, signature:0x5), Unknown (hash:0x8, signature:0x6), SHA256withRSA, SHA384withRSA, SHA512withRSA, SHA1withRSA, SHA256withDSA, Unknown (hash:0x5, signature:0x2), Unknown (hash:0x6, signature:0x2), SHA1withDSA
***
%% Initialized: [Session-8, SSL_NULL_WITH_NULL_NULL]
matching alias: example-mst-02.example.com
matching alias: example-mst-02.example.com
matching alias: example-mst-02.example.com
matching alias: example-mst-02.example.com
qtp2092801316-44, fatal error: 40: no cipher suites in common
javax.net.ssl.SSLHandshakeException: no cipher suites in common
%% Invalidated: [Session-8, SSL_NULL_WITH_NULL_NULL]
qtp2092801316-44, SEND TLSv1.2 ALERT: fatal, description = handshake_failure
qtp2092801316-44, WRITE: TLSv1.2 Alert, length = 2
qtp2092801316-44, fatal: engine already closed. Rethrowing javax.net.ssl.SSLHandshakeException: no cipher suites in common
qtp2092801316-44, called closeOutbound()
qtp2092801316-44, closeOutboundInternal()
Using SSLEngineImpl.

Why am I getting numbers larger than 1000 when I %1000 a number generated by 64 bit mersenne twister engine?

I'm trying to generate a zobrist key for transposition tables in my chess engine.
Here's how I'm generating the 64 bit numbers,
as show here: How to generate 64 bit random numbers?
typedef unsigned long long U64;
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_int_distribution<U64> dist(std::llround(std::pow(2,61)),
std::llround(std::pow(2,62)));
rand function:
U64 ZobristH::random64()
{
U64 ranUI = dist(mt);
return ranUI;
}
In order to try and make sure i'm generating random enough numbers I'm using a test distribution function I found online that looks like this (will later input data into excel and look at distribution):
int sampleSize = 2000;
int distArray[sampleSize];
int t = 0;
while (t < 10)
{
for (int i = 0; i < 10000; i++)
{
distArray[(int)(random64() % (sampleSize / 2))]++;
}
t++;
}
for (int i = 0; i < sampleSize; i++)
{
std::cout << distArray[i] << ", ";
}
the results I'm getting look a little something like this:
416763345, 417123246, 7913280, 7914356, 417726722, 417726718, 19, 83886102,
77332499, 14
Are these the decimal representation of binary numbers below 1000? Or am I doing something completely wrong?
Okay I did this to check out the distribution of random numbers; you can run this short program to generate a text file to look to see what values you are getting. Instead of using a function call I just used a lambda within the for loop and instead of setting the values into the array I wrote the values out to the text file before and after the post increment.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <random>
#include <functional> // may not need - included in almost all of my apps
#include <algorithm> // same as above
typedef unsigned long long U64;
int main( int argc, char** argv ) {
std::random_device rd;
std::mt19937_64 mt( rd() );
std::uniform_int_distribution<U64> dist( std::llround( std::pow( 2, 61 ) ),
std::llround( std::pow( 2, 62 ) ) );
auto lambda = [&] { return dist(mt); };
const int sampleSize = 2000;
// int distArray[sampleSize];
int t = 0;
std::ofstream file( "samples.txt" );
while ( t < 10 ) {
file << "Sample: " << (t+1) << "\n";
for ( int i = 0; i < 10000; i++ ) {
auto val = static_cast<int>( (lambda() % (sampleSize / 2)) );
file << std::setw(5) << i << ": " << std::setw(6) << val << "\t"
<< std::setw(6) << val++ << "\n";
// distArray[...]
}
file << "\n\n";
t++;
}
file.close();
/* for ( int i = 0; i < sampleSize; i++ ) {
std::cout << distArray[i] << "\n";
}*/
// Quick & Dirty Way TO Pause The Console
std::cout << "\nPress any key and enter to quit.\n";
char c;
std::cin >> c;
return 0;
}
Then check out the text file that this program generates and if you scroll through the file you will see the distributions. The first column is the value before the post increment and the second column is after. The largest possible value before the post increment that I have seen is 1,000 and after the post increment is 999. I've built and ran this for both 32 & 64 bit platform versions and have seen similar results for the distributions and that they indeed have a uniform distribution.
Sample.txt - Small Version About 1,000 Entries Out The 1st Sample Set
Sample: 1
0: 342 341
1: 517 516
2: 402 401
3: 741 740
4: 238 237
5: 557 556
6: 35 34
7: 572 571
8: 205 204
9: 353 352
10: 301 300
11: 65 64
12: 223 222
13: 647 646
14: 185 184
15: 535 534
16: 97 96
17: 843 842
18: 716 715
19: 294 293
20: 485 484
21: 648 647
22: 406 405
23: 250 249
24: 245 244
25: 915 914
26: 888 887
27: 986 985
28: 345 344
29: 493 492
30: 654 653
31: 860 859
32: 921 920
33: 526 525
34: 793 792
35: 503 502
36: 939 938
37: 802 801
38: 142 141
39: 806 805
40: 540 539
41: 778 777
42: 787 786
43: 884 883
44: 109 108
45: 842 841
46: 794 793
47: 279 278
48: 821 820
49: 112 111
50: 438 437
51: 402 401
52: 69 68
53: 396 395
54: 196 195
55: 655 654
56: 859 858
57: 674 673
58: 417 416
59: 331 330
60: 632 631
61: 210 209
62: 641 640
63: 737 736
64: 838 837
65: 592 591
66: 562 561
67: 883 882
68: 750 749
69: 726 725
70: 253 252
71: 660 659
72: 57 56
73: 401 400
74: 919 918
75: 851 850
76: 345 344
77: 25 24
78: 300 299
79: 781 780
80: 695 694
81: 220 219
82: 378 377
83: 471 470
84: 281 280
85: 945 944
86: 536 535
87: 407 406
88: 431 430
89: 745 744
90: 32 31
91: 389 388
92: 358 357
93: 582 581
94: 820 819
95: 622 621
96: 459 458
97: 233 232
98: 594 593
99: 509 508
100: 260 259
101: 152 151
102: 148 147
103: 137 136
104: 945 944
105: 244 243
106: 968 967
107: 54 53
108: 420 419
109: 58 57
110: 678 677
111: 715 714
112: 780 779
113: 834 833
114: 241 240
115: 669 668
116: 722 721
117: 608 607
118: 805 804
119: 155 154
120: 220 219
121: 520 519
122: 740 739
123: 184 183
124: 198 197
125: 247 246
126: 115 114
127: 520 519
128: 457 456
129: 864 863
130: 659 658
131: 511 510
132: 718 717
133: 119 118
134: 588 587
135: 113 112
136: 518 517
137: 164 163
138: 375 374
139: 866 865
140: 382 381
141: 526 525
142: 621 620
143: 680 679
144: 147 146
145: 712 711
146: 408 407
147: 486 485
148: 7 6
149: 203 202
150: 741 740
151: 290 289
152: 810 809
153: 960 959
154: 449 448
155: 683 682
156: 997 996
157: 454 453
158: 131 130
159: 427 426
160: 157 156
161: 3 2
162: 427 426
163: 554 553
164: 806 805
165: 228 227
166: 431 430
167: 174 173
168: 845 844
169: 121 120
170: 397 396
171: 770 769
172: 17 16
173: 761 760
174: 736 735
175: 629 628
176: 772 771
177: 417 416
178: 739 738
179: 226 225
180: 301 300
181: 217 216
182: 746 745
183: 344 343
184: 607 606
185: 927 926
186: 428 427
187: 385 384
188: 287 286
189: 537 536
190: 705 704
191: 649 648
192: 127 126
193: 252 251
194: 160 159
195: 390 389
196: 282 281
197: 66 65
198: 659 658
199: 844 843
200: 358 357
201: 360 359
202: 872 871
203: 495 494
204: 695 694
205: 988 987
206: 969 968
207: 641 640
208: 799 798
209: 30 29
210: 109 108
211: 675 674
212: 345 344
213: 309 308
214: 807 806
215: 283 282
216: 457 456
217: 193 192
218: 972 971
219: 330 329
220: 914 913
221: 508 507
222: 624 623
223: 254 253
224: 342 341
225: 69 68
226: 918 917
227: 551 550
228: 148 147
229: 645 644
230: 905 904
231: 503 502
232: 980 979
233: 881 880
234: 137 136
235: 202 201
236: 808 807
237: 988 987
238: 497 496
239: 506 505
240: 576 575
241: 671 670
242: 874 873
243: 217 216
244: 808 807
245: 741 740
246: 14 13
247: 206 205
248: 894 893
249: 180 179
250: 4 3
251: 27 26
252: 62 61
253: 203 202
254: 392 391
255: 868 867
256: 673 672
257: 881 880
258: 664 663
259: 831 830
260: 293 292
261: 916 915
262: 860 859
263: 487 486
264: 642 641
265: 161 160
266: 881 880
267: 233 232
268: 423 422
269: 12 11
270: 398 397
271: 993 992
272: 323 322
273: 878 877
274: 114 113
275: 42 41
276: 58 57
277: 398 397
278: 878 877
279: 64 63
280: 873 872
281: 841 840
282: 506 505
283: 412 411
284: 545 544
285: 887 886
286: 17 16
287: 504 503
288: 350 349
289: 772 771
290: 16 15
291: 597 596
292: 553 552
293: 25 24
294: 324 323
295: 242 241
296: 580 579
297: 479 478
298: 702 701
299: 640 639
300: 173 172
301: 918 917
302: 678 677
303: 714 713
304: 258 257
305: 97 96
306: 304 303
307: 80 79
308: 394 393
309: 940 939
310: 985 984
311: 651 650
312: 42 41
313: 179 178
314: 672 671
315: 915 914
316: 160 159
317: 332 331
318: 887 886
319: 370 369
320: 850 849
321: 730 729
322: 395 394
323: 889 888
324: 114 113
325: 505 504
326: 381 380
327: 578 577
328: 762 761
329: 896 895
330: 793 792
331: 295 294
332: 488 487
333: 599 598
334: 182 181
335: 25 24
336: 623 622
337: 396 395
338: 898 897
339: 981 980
340: 645 644
341: 806 805
342: 205 204
343: 404 403
344: 234 233
345: 36 35
346: 659 658
347: 285 284
348: 62 61
349: 608 607
350: 632 631
351: 825 824
352: 585 584
353: 685 684
354: 14 13
355: 828 827
356: 720 719
357: 871 870
358: 88 87
359: 716 715
360: 879 878
361: 650 649
362: 464 463
363: 898 897
364: 930 929
365: 194 193
366: 997 996
367: 105 104
368: 776 775
369: 398 397
370: 962 961
371: 434 433
372: 954 953
373: 548 547
374: 989 988
375: 943 942
376: 229 228
377: 866 865
378: 554 553
379: 567 566
380: 379 378
381: 564 563
382: 738 737
383: 468 467
384: 660 659
385: 693 692
386: 784 783
387: 739 738
388: 662 661
389: 474 473
390: 545 544
391: 958 957
392: 703 702
393: 316 315
394: 571 570
395: 95 94
396: 497 496
397: 672 671
398: 676 675
399: 821 820
400: 368 367
401: 7 6
402: 817 816
403: 221 220
404: 839 838
405: 578 577
406: 635 634
407: 453 452
408: 70 69
409: 764 763
410: 78 77
411: 968 967
412: 295 294
413: 483 482
414: 392 391
415: 23 22
416: 389 388
417: 678 677
418: 150 149
419: 863 862
420: 677 676
421: 676 675
422: 455 454
423: 405 404
424: 126 125
425: 753 752
426: 821 820
427: 328 327
428: 773 772
429: 596 595
430: 645 644
431: 829 828
432: 377 376
433: 444 443
434: 813 812
435: 395 394
436: 794 793
437: 641 640
438: 98 97
439: 827 826
440: 824 823
441: 681 680
442: 736 735
443: 288 287
444: 560 559
445: 781 780
446: 556 555
447: 327 326
448: 820 819
449: 859 858
450: 686 685
451: 919 918
452: 267 266
453: 128 127
454: 583 582
455: 446 445
456: 783 782
457: 712 711
458: 378 377
459: 367 366
460: 52 51
461: 316 315
462: 780 779
463: 398 397
464: 435 434
465: 788 787
466: 380 379
467: 235 234
468: 748 747
469: 429 428
470: 91 90
471: 675 674
472: 853 852
473: 674 673
474: 277 276
475: 179 178
476: 264 263
477: 511 510
478: 514 513
479: 979 978
480: 845 844
481: 728 727
482: 904 903
483: 874 873
484: 750 749
485: 659 658
486: 376 375
487: 713 712
488: 393 392
489: 538 537
490: 896 895
491: 879 878
492: 347 346
493: 819 818
494: 210 209
495: 707 706
496: 869 868
497: 319 318
498: 832 831
499: 498 497
500: 71 70
501: 290 289
502: 861 860
503: 295 294
504: 888 887
505: 515 514
506: 222 221
507: 661 660
508: 813 812
509: 969 968
510: 547 546
511: 900 899
512: 58 57
513: 805 804
514: 428 427
515: 453 452
516: 23 22
517: 969 968
518: 718 717
519: 775 774
520: 395 394
521: 521 520
522: 522 521
523: 465 464
524: 317 316
525: 216 215
526: 254 253
527: 696 695
528: 677 676
529: 21 20
530: 318 317
531: 301 300
532: 142 141
533: 877 876
534: 486 485
535: 981 980
536: 516 515
537: 254 253
538: 328 327
539: 385 384
540: 2 1
541: 405 404
542: 387 386
543: 794 793
544: 48 47
545: 641 640
546: 814 813
547: 981 980
548: 354 353
549: 281 280
550: 561 560
551: 683 682
552: 247 246
553: 739 738
554: 370 369
555: 799 798
556: 680 679
557: 915 914
558: 638 637
559: 254 253
560: 705 704
561: 320 319
562: 640 639
563: 487 486
564: 47 46
565: 852 851
566: 749 748
567: 419 418
568: 300 299
569: 507 506
570: 141 140
571: 972 971
572: 895 894
573: 988 987
574: 279 278
575: 268 267
576: 392 391
577: 530 529
578: 679 678
579: 855 854
580: 246 245
581: 645 644
582: 624 623
583: 417 416
584: 203 202
585: 30 29
586: 9 8
587: 585 584
588: 573 572
589: 471 470
590: 504 503
591: 290 289
592: 588 587
593: 230 229
594: 351 350
595: 651 650
596: 615 614
597: 502 501
598: 352 351
599: 472 471
// 600 - 699 omitted to make space to fit answer
700: 247 246
701: 894 893
702: 809 808
703: 382 381
704: 81 80
705: 574 573
706: 507 506
707: 508 507
708: 569 568
709: 947 946
710: 384 383
711: 14 13
712: 627 626
713: 951 950
714: 825 824
715: 657 656
716: 206 205
717: 598 597
718: 300 299
719: 266 265
720: 909 908
721: 206 205
722: 126 125
723: 841 840
724: 586 585
725: 348 347
726: 100 99
727: 361 360
728: 695 694
729: 556 555
730: 66 65
731: 5 4
732: 686 685
733: 488 487
734: 149 148
735: 622 621
736: 476 475
737: 488 487
738: 371 370
739: 331 330
740: 965 964
741: 141 140
742: 396 395
743: 917 916
744: 31 30
745: 924 923
746: 283 282
747: 369 368
748: 519 518
749: 830 829
750: 688 687
751: 374 373
752: 41 40
753: 418 417
754: 766 765
755: 854 853
756: 453 452
757: 521 520
758: 640 639
759: 185 184
760: 41 40
761: 125 124
762: 723 722
763: 341 340
764: 142 141
765: 754 753
766: 459 458
767: 899 898
768: 166 165
769: 374 373
770: 572 571
771: 304 303
772: 352 351
773: 235 234
774: 879 878
775: 736 735
776: 576 575
777: 56 55
778: 102 101
779: 170 169
780: 208 207
781: 135 134
782: 919 918
783: 599 598
784: 37 36
785: 997 996
786: 922 921
787: 502 501
788: 29 28
789: 173 172
790: 54 53
791: 601 600
792: 535 534
793: 64 63
794: 723 722
795: 491 490
796: 685 684
797: 58 57
798: 272 271
799: 261 260
800: 81 80
801: 149 148
802: 129 128
803: 712 711
804: 377 376
805: 151 150
806: 514 513
807: 14 13
808: 838 837
809: 347 346
810: 517 516
811: 442 441
812: 264 263
813: 883 882
814: 447 446
815: 140 139
816: 195 194
817: 841 840
818: 218 217
819: 858 857
820: 28 27
821: 222 221
822: 223 222
823: 906 905
824: 873 872
825: 492 491
826: 826 825
827: 738 737
828: 307 306
829: 185 184
830: 525 524
831: 449 448
832: 646 645
833: 686 685
834: 942 941
835: 433 432
836: 881 880
837: 824 823
838: 641 640
839: 290 289
840: 897 896
841: 4 3
842: 124 123
843: 679 678
844: 524 523
845: 424 423
846: 282 281
847: 625 624
848: 414 413
849: 647 646
850: 129 128
851: 395 394
852: 720 719
853: 318 317
854: 262 261
855: 402 401
856: 413 412
857: 139 138
858: 549 548
859: 472 471
860: 162 161
861: 605 604
862: 67 66
863: 980 979
864: 465 464
865: 912 911
866: 219 218
867: 648 647
868: 619 618
869: 331 330
870: 625 624
871: 360 359
872: 425 424
873: 935 934
874: 89 88
875: 641 640
876: 535 534
877: 404 403
878: 966 965
879: 27 26
880: 281 280
881: 637 636
882: 57 56
883: 152 151
884: 156 155
885: 813 812
886: 340 339
887: 181 180
888: 921 920
889: 306 305
890: 101 100
891: 178 177
892: 417 416
893: 845 844
894: 904 903
895: 295 294
896: 346 345
897: 654 653
898: 357 356
899: 929 928
900: 195 194
901: 499 498
902: 377 376
903: 727 726
904: 570 569
905: 853 852
906: 71 70
907: 580 579
908: 642 641
909: 889 888
910: 559 558
911: 134 133
912: 324 323
913: 120 119
914: 991 990
915: 6 5
916: 708 707
917: 347 346
918: 929 928
919: 454 453
920: 636 635
921: 218 217
922: 739 738
923: 715 714
924: 87 86
925: 782 781
926: 670 669
927: 845 844
928: 79 78
929: 730 729
930: 58 57
931: 216 215
932: 711 710
933: 898 897
934: 871 870
935: 388 387
936: 389 388
937: 944 943
938: 927 926
939: 88 87
940: 617 616
941: 940 939
942: 948 947
943: 927 926
944: 646 645
945: 125 124
946: 615 614
947: 846 845
948: 705 704
949: 998 997
950: 304 303
951: 346 345
952: 675 674
953: 783 782
954: 129 128
955: 69 68
956: 17 16
957: 646 645
958: 559 558
959: 62 61
960: 807 806
961: 571 570
962: 54 53
963: 297 296
964: 771 770
965: 972 971
966: 829 828
967: 786 785
968: 650 649
969: 101 100
970: 705 704
971: 690 689
972: 365 364
973: 304 303
974: 82 81
975: 776 775
976: 495 494
977: 586 585
978: 556 555
979: 77 76
980: 640 639
981: 161 160
982: 910 909
983: 46 45
984: 43 42
985: 162 161
986: 514 513
987: 654 653
988: 668 667
989: 126 125
990: 254 253
991: 133 132
992: 398 397
993: 993 992
994: 357 356
995: 298 297
996: 519 518
997: 904 903
998: 382 381
999: 28 27
1000: 19 18
1001: 939 938
1002: 868 867
1003: 888 887
1004: 576 575
1005: 183 182
1006: 174 173
1007: 679 678
1008: 831 830
1009: 464 463
1010: 876 875
1011: 738 737
1012: 447 446
1013: 385 384
1014: 271 270
1015: 38 37
1016: 28 27
1017: 451 450
1018: 162 161
1019: 847 846
1020: 430 429
1021: 849 848
1022: 207 206
1023: 196 195
1024: 42 41
1025: 709 708
1026: 557 556
1027: 173 172
1028: 788 787
1029: 160 159
1030: 535 534
1031: 555 554
1032: 252 251
1033: 111 110
1034: 476 475
1035: 780 779
1036: 44 43
1037: 190 189
1038: 443 442
1039: 655 654
1040: 7 6
1041: 845 844
1042: 856 855
1043: 274 273
1044: 933 932
1045: 336 335
1046: 185 184
1047: 580 579
1048: 807 806
1049: 286 285
1050: 409 408
1051: 347 346
1052: 461 460
1053: 624 623
1054: 378 377
1055: 903 902
1056: 483 482
1057: 838 837
1058: 809 808
1059: 919 918
1060: 544 543
1061: 458 457
1062: 121 120
1063: 192 191
1064: 126 125
1065: 843 842
1066: 927 926
1067: 390 389
1068: 567 566
1069: 1000 999
Entry 1069 is the first occurrence in this sample set to reach 1,000. I've ran this about a dozen times both in 32bit and 64bit modes and I did not see any value go above 1,000.
I'm not sure but I think that this line in your code is what is giving you your problem(s):
distArray[(int)(random64() % (sampleSize / 2))]++;

Processing elements in each line into multiple lines

I need help with processing a file, which contains multiple lines with comma separated elements. The file looks as shown below:
File-1.txt
54, 75, 19, 123, 74, 15, 10, 117
54, 75, 19, 45, 74, 15, 10, 117
54, 29, 19, 123, 74, 15, 10, 117
54, 29, 19, 45, 74, 15, 10, 117
I want to convert the comma seperated values of each line into two columns separated by tab, as shown below:
Output_File:
54 75
75 19
19 123
123 74
74 15
15 10
10 117
Likewise, each row saved into a separated file named with the first and last numbers of the original row followed by the line number as shown below
Output_file 1
ABC-54_117-1
54 75
75 19
19 123
123 74
74 15
15 10
10 117
Output_file 2
ABC-54_117-2
54 75
75 19
19 45
45 74
74 15
15 10
10 117
and so on for other two rows also. Here in this case it is 4 rows in a file, but I have few files with many rows, which needs to be processed in the same way. I tried scripts with awk, sed but couldn't crack it at all.
Any help will be appreciated.
You can use this awk:
awk -F', +' '{f=$1"_"$NF"_"NR; for (i=1; i<NF; i++){print $i,$(i+1)>f}}' OFS='\t' file
Output:
$ ls
54_117_1 54_117_2 54_117_3 54_117_4
$ cat 54_117_2
54 75
75 19
19 45
45 74
74 15
15 10
10 117
The complete solution would be:
awk -F, '{ cnt++;for (i=1;i<=7;i++) { system("echo \""$i" "$(i+1)"\" >> \"ABC-"$1"_"gensub(" ","","g",$8)"_"cnt"\"") } }' File-1.txt
We have first increment cnt for each record in File-1.txt. We know that there are 8 comma delimited fields in each line so we use a for loop with 8 iterations and inside the loop use the system command to echo the pairs of variables out to a file constructed with the cnt variable and the 8th delimited field. The function gensub is used to remove any spaces in the 8th field.

How to extract Photoshop curve points to RGB number array?

Hi I made some filter effects using Photoshop curves and they look like this:
Is there a way I can extract each one of the 256 numbers from each color so it is a number array like this?
var r = [0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 44, 45, 47, 48, 49, 52, 54, 55, 57, 59, 60, 62, 65, 67, 69, 70, 72, 74, 77, 79, 81, 83, 86, 88, 90, 92, 94, 97, 99, 101, 103, 107, 109, 111, 112, 116, 118, 120, 124, 126, 127, 129, 133, 135, 136, 140, 142, 143, 145, 149, 150, 152, 155, 157, 159, 162, 163, 165, 167, 170, 171, 173, 176, 177, 178, 180, 183, 184, 185, 188, 189, 190, 192, 194, 195, 196, 198, 200, 201, 202, 203, 204, 206, 207, 208, 209, 211, 212, 213, 214, 215, 216, 218, 219, 219, 220, 221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 245, 246, 247, 247, 248, 248, 249, 249, 249, 250, 251, 251, 252, 252, 252, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
Sorry for the question if it's stupid, i'm not even sure what i'm asking, it's late.
UPDATE: following Mark Setchell's answer, i was able to create a saved.ppm file with these values inside it.
The last step was to extract the RGB values from this long string of numbers, Red is the 0th, 3nd, 6th number, Green is the 1st, 4th, 7th number etc.
For anyone else's interest, I was trying to create a filter on Photoshop curves, then extract its RGB values and apply it using pixel cross processing on HTML Canvas, similar to a demo shown here.
Here is a totally different, and simpler way of doing it. Save the data below in a file called ramp.ppm - it is a Portable Pixmap format from the NetPBM suite see Wikipedia here. It is a black-to-white greyscale ramp 256 pixels wide and 1 pixel tall.
Load that into Photoshop and apply your curve to it then save as a PNG file.
P3
256 1
255
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
12 12 12
13 13 13
14 14 14
15 15 15
16 16 16
17 17 17
18 18 18
19 19 19
20 20 20
21 21 21
22 22 22
23 23 23
24 24 24
25 25 25
26 26 26
27 27 27
28 28 28
29 29 29
30 30 30
31 31 31
32 32 32
33 33 33
34 34 34
35 35 35
36 36 36
37 37 37
38 38 38
39 39 39
40 40 40
41 41 41
42 42 42
43 43 43
44 44 44
45 45 45
46 46 46
47 47 47
48 48 48
49 49 49
50 50 50
51 51 51
52 52 52
53 53 53
54 54 54
55 55 55
56 56 56
57 57 57
58 58 58
59 59 59
60 60 60
61 61 61
62 62 62
63 63 63
64 64 64
65 65 65
66 66 66
67 67 67
68 68 68
69 69 69
70 70 70
71 71 71
72 72 72
73 73 73
74 74 74
75 75 75
76 76 76
77 77 77
78 78 78
79 79 79
80 80 80
81 81 81
82 82 82
83 83 83
84 84 84
85 85 85
86 86 86
87 87 87
88 88 88
89 89 89
90 90 90
91 91 91
92 92 92
93 93 93
94 94 94
95 95 95
96 96 96
97 97 97
98 98 98
99 99 99
100 100 100
101 101 101
102 102 102
103 103 103
104 104 104
105 105 105
106 106 106
107 107 107
108 108 108
109 109 109
110 110 110
111 111 111
112 112 112
113 113 113
114 114 114
115 115 115
116 116 116
117 117 117
118 118 118
119 119 119
120 120 120
121 121 121
122 122 122
123 123 123
124 124 124
125 125 125
126 126 126
127 127 127
128 128 128
129 129 129
130 130 130
131 131 131
132 132 132
133 133 133
134 134 134
135 135 135
136 136 136
137 137 137
138 138 138
139 139 139
140 140 140
141 141 141
142 142 142
143 143 143
144 144 144
145 145 145
146 146 146
147 147 147
148 148 148
149 149 149
150 150 150
151 151 151
152 152 152
153 153 153
154 154 154
155 155 155
156 156 156
157 157 157
158 158 158
159 159 159
160 160 160
161 161 161
162 162 162
163 163 163
164 164 164
165 165 165
166 166 166
167 167 167
168 168 168
169 169 169
170 170 170
171 171 171
172 172 172
173 173 173
174 174 174
175 175 175
176 176 176
177 177 177
178 178 178
179 179 179
180 180 180
181 181 181
182 182 182
183 183 183
184 184 184
185 185 185
186 186 186
187 187 187
188 188 188
189 189 189
190 190 190
191 191 191
192 192 192
193 193 193
194 194 194
195 195 195
196 196 196
197 197 197
198 198 198
199 199 199
200 200 200
201 201 201
202 202 202
203 203 203
204 204 204
205 205 205
206 206 206
207 207 207
208 208 208
209 209 209
210 210 210
211 211 211
212 212 212
213 213 213
214 214 214
215 215 215
216 216 216
217 217 217
218 218 218
219 219 219
220 220 220
221 221 221
222 222 222
223 223 223
224 224 224
225 225 225
226 226 226
227 227 227
228 228 228
229 229 229
230 230 230
231 231 231
232 232 232
233 233 233
234 234 234
235 235 235
236 236 236
237 237 237
238 238 238
239 239 239
240 240 240
241 241 241
242 242 242
243 243 243
244 244 244
245 245 245
246 246 246
247 247 247
248 248 248
249 249 249
250 250 250
251 251 251
252 252 252
253 253 253
254 254 254
255 255 255
If you have Linux, and you have ImageMagick, you can then convert the saved PNG file back into a PPM file with
convert saved.png -compress none saved.ppm
The file saved.ppm will then show you the output of your curve for each input value in the greyscale ramp - in effect it will be the 256 values you are looking for.
If you don't have ImageMagick, just give me the PNG file and I'll convert it for you.
I don't feel like writing the code today, least of all when you are not too sure what you are up to! However, what you are asking is perfectly achievable.
If you save the curve you have created (the Save option is in the top right menu), you will get a .ACV file. The format of this file is given here if you scroll down to the section entitled Curves. It is a pretty simple format with just an identifier and a version number then a count of the number of points that you have defined for your curve, i.e. 6 in your case. Then, for each point, the 4 coordinates. These can be pretty easily extracted with Perl or similar.
You could then fit a curve to those points, probably using GNUplot, and interpolate to find the points you are looking for.
Excerpt from referenced document:
Here is an extract from some code I wrote in Perl that actually writes a .ACV file. I know you will actually want to read one, bit you'll get the idea of the byte packing technique...
#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;
use Data::Dumper;
my $Debug=1; # 1=print debug messages, 0=don't
my $NPOINTS=5; # Number of points in curve we create
....
.... other stuff
....
# Work out name of the curve file = image basename + acv
my $curvefile=substr($imagename,0,rindex($imagename,'.')) . ".acv";
open(my $out,'>:raw',$curvefile) or die "Unable to open: $!";
print $out pack("s>",4); # Version=4
print $out pack("s>",4); # Number of curves in file = Master NULL curve + R + G + B
print $out pack("s>",2); # Master NULL curve with 2 points for all channels
print $out pack("s>",0 ),pack("s>",0 ); # 0 out, 0 in
print $out pack("s>",255),pack("s>",255); # 255 out, 255 in
print $out pack("s>",2+$NPOINTS); # Red curve
print $out pack("s>",0 ),pack("s>",0 ); # 0 out, 0 in
for($p=0;$p<$NPOINTS;$p++){
print $out pack("s>",$Rpoint[$p]),pack("s>",$greypoint[$p]);
}
print $out pack("s>",255),pack("s>",255); # 255 out, 255 in
print $out pack("s>",2+$NPOINTS); # Green curve
print $out pack("s>",0 ),pack("s>",0 ); # 0 out, 0 in
for($p=0;$p<$NPOINTS;$p++){
print $out pack("s>",$Gpoint[$p]),pack("s>",$greypoint[$p]);
}
print $out pack("s>",255),pack("s>",255); # 255 out, 255 in
print $out pack("s>",2+$NPOINTS); # Blue curve
print $out pack("s>",0 ),pack("s>",0 ); # 0 out, 0 in
for($p=0;$p<$NPOINTS;$p++){
print $out pack("s>",$Bpoint[$p]),pack("s>",$greypoint[$p]);
}
print $out pack("s>",255),pack("s>",255); # 255 out, 255 in
close($out);

Cannot solve Hungarian Algorithm

I'm trying to implementing a function to solve the hungarian algorithm and i think that there is something i have misunderstood about the algorithm.
For testing purposes i'm using this c++ code from google that is supposed to work.
But when i test this 14x11 matrix, it says that it is not possible to solve:
[ 0 0 0 0 0 0 0 0 0 0 0 ]
[ 53 207 256 207 231 348 348 348 231 244 244 ]
[ 240 33 67 33 56 133 133 133 56 33 33 ]
[ 460 107 200 107 122 324 324 324 122 33 33 ]
[ 167 340 396 340 422 567 567 567 422 442 442 ]
[ 167 367 307 367 433 336 336 336 433 158 158 ]
[ 160 20 37 20 31 70 70 70 31 22 22 ]
[ 200 307 393 307 222 364 364 364 222 286 286 ]
[ 33 153 152 153 228 252 252 252 228 78 78 ]
[ 93 140 185 140 58 118 118 118 58 44 44 ]
[ 0 7 22 7 19 58 58 58 19 0 0 ]
[ 67 153 241 153 128 297 297 297 128 39 39 ]
[ 73 253 389 253 253 539 539 539 253 36 36 ]
[ 173 267 270 267 322 352 352 352 322 231 231 ]
C++ code for creating the array: (in case someone wants to test it by using the C++ example i provided)
int r[14*11] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 207, 256, 207, 231, 348, 348, 348, 231, 244, 244, 240, 33, 67, 33, 56, 133, 133, 133, 56, 33, 33, 460, 107, 200, 107, 122, 324, 324, 324, 122, 33, 33, 167, 340, 396, 340, 422, 567, 567, 567, 422, 442, 442, 167, 367, 307, 367, 433, 336, 336, 336, 433, 158, 158, 160, 20, 37, 20, 31, 70, 70, 70, 31, 22, 22, 200, 307, 393, 307, 222, 364, 364, 364, 222, 286, 286, 33, 153, 152, 153, 228, 252, 252, 252, 228, 78, 78, 93, 140, 185, 140, 58, 118, 118, 118, 58, 44, 44, 0, 7, 22, 7, 19, 58, 58, 58, 19, 0, 0, 67, 153, 241, 153, 128, 297, 297, 297, 128, 39, 39, 73, 253, 389, 253, 253, 539, 539, 539, 253, 36, 36, 173, 267, 270, 267, 322, 352, 352, 352, 322, 231, 231};
If I run my implementation to reduce the number of zeros (so they can get covered by the minimum number of lines- step 9 in wikihow's link provided at the top -) I get the following matrix where i have to find the 0 combination unique for row and column.
The problem is that it is impossible to solve since the columns 10 and 11 (the ones bold) only have one 0 each one and it is in the same row.
Row 1 : [ 240 140 225 140 206 339 339 339 206 215 215 0 0 0 ]
Row 2 : [ 254 0 37 0 43 58 58 58 43 38 38 67 67 67 ]
Row 3 : [ 0 107 158 107 151 206 206 206 151 182 182 0 0 0 ]
Row 4 : [ 0 253 245 253 304 235 235 235 304 402 402 220 220 220 ]
Row 5 : [ 300 27 56 27 11 0 0 0 11 0 0 227 227 227 ]
Row 6 : [ 300 0 145 0 0 230 230 230 0 284 284 227 227 227 ]
Row 7 : [ 80 120 188 120 176 269 269 269 176 193 193 0 0 0 ]
Row 8 : [ 207 0 0 0 151 143 143 143 151 96 96 167 167 167 ]
Row 9 : [ 229 9 95 9 0 110 110 110 0 159 159 22 22 22 ]
Row 10 : [ 147 0 40 0 148 221 221 221 148 171 171 0 0 0 ]
Row 11 : [ 240 133 203 133 187 282 282 282 187 215 215 0 0 0 ]
Row 12 : [ 189 3 0 3 94 58 58 58 94 192 192 16 16 16 ]
Row 13 : [ 367 87 36 87 153 0 0 0 153 379 379 200 200 200 ]
Row 14 : [ 194 0 82 0 11 115 115 115 11 112 112 127 127 127 ]
Is there any kind of limitation with this method? Or is just me, making a bad implementation of the algorithm? In this case, why "is the supposed to work" example not working either?
Any suggestion would be appreciate, or if you know any trick or suggestion to help finding the minimum number of lines to cover zeros, please let me know.
Thanks in advance,
Is there any kind of limitation with this method?
Yes. That line drawing method will only properly work if you have made the maximum number of assignments at each step. I don't particularly feel like working this out by hand to prove it, but I assume that the code you are using does not accomplish that for this particular matrix. I decided to work it out (aka procrastinate) as best as I can figure from the lack of documentation, and it doesn't actually have a problem with covering all zeroes with the minimum number of lines. It's just bad at making assignments.
Every implementation of the Hungarian Algorithm I have found online will not work. They unfortunately all copy each other without actually learning the math behind it, and thus they all get it wrong. I have implemented something similar to what Munkres describes in his article "Algorithms for the Assignment and Transportation Problems", published in 1957. My code gives the results: (0,1), (1,3), (2,8), (3,2), (9,12), (10,11), (4,9), (8,7), (5,10), (6,6), (7,0) for a minimum cost of 828.
You can view my code here: http://www.mediafire.com/view/1yss74lxb7kro2p/APS.h
ps: Thanks for providing that C++ array. I wasn't looking forward to typing it myself.
pps: Here's your matrix, properly spaced:
0 0 0 0 0 0 0 0 0 0 0
53 207 256 207 231 348 348 348 231 244 244
240 33 67 33 56 133 133 133 56 33 33
460 107 200 107 122 324 324 324 122 33 33
167 340 396 340 422 567 567 567 422 442 442
167 367 307 367 433 336 336 336 433 158 158
160 20 37 20 31 70 70 70 31 22 22
200 307 393 307 222 364 364 364 222 286 286
33 153 152 153 228 252 252 252 228 78 78
93 140 185 140 58 118 118 118 58 44 44
0 7 22 7 19 58 58 58 19 0 0
67 153 241 153 128 297 297 297 128 39 39
73 253 389 253 253 539 539 539 253 36 36
173 267 270 267 322 352 352 352 322 231 231
Note in the link you provide section (2) that you add dummy rows or columns to make sure the matrix is square.
Now that you have a square matrix, there are a large number of different matchings which link together each row with its own column and vice versa. The solution, or solutions, is simply one of these matchings that has the lowest possible cost, so there should always be a solution.

Resources