As an addendum, in general to find if q is a quadratic residue modulo n, you need to calculate the jacobi symbol (n/q), (not to be confused with the jacobian).
I wrote a method to do this... in Java... https://github.com/jonghough/Java-Numbers/blob/master/src/algorithms/JacobiSymbol.java but I think writing a method in J would not be difficult, although it doesn't seem like you need one. -------------------------------------------- On Tue, 1/5/16, Devon McCormick <[email protected]> wrote: Subject: [Jprogramming] Prime-based selection oddity To: "J-programming forum" <[email protected]> Date: Tuesday, January 5, 2016, 11:13 AM Recently I was looking at how I might generate something that look like an encryption key and noticed this oddity: #val=. '0123456789ABCDEF' 16 val{~(#val)|2^~p:i.128 49919919191919199991119119199119199199199911919199111911919199911991991119919911991119119191199191999991919111191911919991999991 frtab val{~(#val)|2^~p:i.128 +--+-+ |1 |4| +--+-+ |68|9| +--+-+ |59|1| +--+-+ Where "frtab" is a frequency table generator: frtab=: 3 : 0 cts=. #&>y</.y NB. # unique items... if. -.isNum y do. NB. Special case enclosed, text mat, text vec, if. (L.=0:) y do. (<"0 cts),.<"0 ~.y else. if. 2=#$y do. (<"0 cts),.<"1 ~.y else. (<"0 cts),.<"0 ~.y end. end. else. cts,.~.y end. NB. and simple numeric vec. NB.EG (1 2 3 2 1,. 11 22 33 222 99) -: frtab 11 22 22 33 33 33 222 222 99 ) Any obvious reason why the 16| of squares of primes should return only "1" and "9" for this sample? -- Devon McCormick, CFA Quantitative Consultant ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
