You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Eldar Agalarov (Created) (JIRA)" <ji...@apache.org> on 2011/11/20 02:11:51 UTC

[jira] [Created] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Add support for fast cryptographically secure pseudorandom number generator ISAAC
---------------------------------------------------------------------------------

                 Key: MATH-710
                 URL: https://issues.apache.org/jira/browse/MATH-710
             Project: Commons Math
          Issue Type: New Feature
    Affects Versions: 2.2
            Reporter: Eldar Agalarov


Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG. Java code is below:

import java.io.Serializable;

public final class ISAACRandom extends AbstractRandom implements Serializable, Cloneable {

    private static final long serialVersionUID = 7288197941165002400L;

    private static final int SIZE_L = 8;                /* log of size of rsl[] and mem[] */
    private static final int SIZE = 1 << SIZE_L;        /* size of rsl[] and mem[] */
    private static final int H_SIZE = SIZE >> 1;        /* half-size of rsl[] and mem[] */
    private static final int MASK = SIZE - 1 << 2;      /* for pseudorandom lookup */
    private static final int GLD_RATIO = 0x9e3779b9;    /* the golden ratio */
    private static final long SEED_MASK = 0xffffffffL;

    private int[] rsl;                                  /* the results given to the user */
    private int[] mem;                                  /* the internal state */
    private int[] arr;

    private int count;                                  /* count through the results in rsl[] */
    private int a;                                      /* accumulator */
    private int b;                                      /* the last result */
    private int c;                                      /* counter, guarantees cycle is at least 2^^40 */
    private transient int x;
    private transient int i;
    private transient int j;


    public ISAACRandom() {
        this(System.currentTimeMillis());
    }

    public ISAACRandom(long seed) {
        allocArrays();
        setSeed(seed);
    }

    public ISAACRandom(int[] seed) {
        allocArrays();
        setSeed(seed);
    }

    private void allocArrays() {
        rsl = new int[SIZE];
        mem = new int[SIZE];
        arr = new int[8];
    }

    @Override
    public void setSeed(int seed) {
        setSeed(new int[]{seed});
    }

    @Override
    public void setSeed(long seed) {
        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & SEED_MASK)});
    }

    @Override
    public void setSeed(int[] seed) {
        int seedLen = seed.length, rslLen = rsl.length;
        System.arraycopy(seed, 0, rsl, 0, Math.min(seedLen, rslLen));
        if (seedLen < rslLen) {
            for (i = seedLen; i < rslLen; i++) {
                long k = rsl[i - seedLen];
                rsl[i] = (int) (0x6c078965L * (k ^ k >> 30) + i & SEED_MASK);
            }
        }
        initState();
        isaac();
        count = SIZE - 1;
    }

    @Override
    protected int next(int bits) {
        if (count < 0) {
            isaac();
            count = SIZE - 1;
        }
        return rsl[count--] >>> 32 - bits;
    }

    private void isaac() {
        i = 0; j = H_SIZE; b += ++c;
        while (i < H_SIZE) isaac2();
        j = 0;
        while (j < H_SIZE) isaac2();
    }

    private void isaac2() {
        x = mem[i]; a ^= a <<  13; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>>  6; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a <<   2; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>> 16; a += mem[j++]; isaac3();
    }

    private void isaac3() {
        mem[i] = mem[(x & MASK) >> 2] + a + b;
        b = mem[(mem[i] >> SIZE_L & MASK) >> 2] + x;
        rsl[i++] = b;
    }

    private void initState() {
        a = b = c = 0;
        arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = arr[5] = arr[6] = arr[7] = GLD_RATIO;
        for (i = 0; i < 4; i++) shuffle();
        for (i = 0; i < SIZE; i++) mem[i] = rsl[i] = 0;
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += rsl[i];     arr[1] += rsl[i + 1]; arr[2] += rsl[i + 2];
            arr[3] += rsl[i + 3]; arr[4] += rsl[i + 4]; arr[5] += rsl[i + 5];
            arr[6] += rsl[i + 6]; arr[7] += rsl[i + 7];
            shuffle(); setState();
        }
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += mem[i];     arr[1] += mem[i + 1]; arr[2] += mem[i + 2];
            arr[3] += mem[i + 3]; arr[4] += mem[i + 4]; arr[5] += mem[i + 5];
            arr[6] += mem[i + 6]; arr[7] += mem[i + 7];
            shuffle(); setState();
        }
    }

    private void shuffle() {
        arr[0] ^= arr[1] <<  11; arr[3] += arr[0]; arr[1] += arr[2];
        arr[1] ^= arr[2] >>>  2; arr[4] += arr[1]; arr[2] += arr[3];
        arr[2] ^= arr[3] <<   8; arr[5] += arr[2]; arr[3] += arr[4];
        arr[3] ^= arr[4] >>> 16; arr[6] += arr[3]; arr[4] += arr[5];
        arr[4] ^= arr[5] <<  10; arr[7] += arr[4]; arr[5] += arr[6];
        arr[5] ^= arr[6] >>>  4; arr[0] += arr[5]; arr[6] += arr[7];
        arr[6] ^= arr[7] <<   8; arr[1] += arr[6]; arr[7] += arr[0];
        arr[7] ^= arr[0] >>>  9; arr[2] += arr[7]; arr[0] += arr[1];
    }

    private void setState() {
        mem[i] =     arr[0]; mem[i + 1] = arr[1]; mem[i + 2] = arr[2];
        mem[i + 3] = arr[3]; mem[i + 4] = arr[4]; mem[i + 5] = arr[5];
        mem[i + 6] = arr[6]; mem[i + 7] = arr[7];
    }

    @Override
    public ISAACRandom clone() {
        try {
            ISAACRandom cloned = (ISAACRandom) super.clone();
            cloned.rsl = rsl.clone();
            cloned.mem = mem.clone();
            cloned.arr = arr.clone();
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new InternalError(e.getMessage());
        }
    }
}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Luc Maisonobe (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe updated MATH-710:
-------------------------------

         Priority: Minor  (was: Major)
    Fix Version/s: 3.0
         Assignee: Luc Maisonobe
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACRandom.java
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACRandom.java

Java code of ISAAC CSPRNG. Translated to Java from original C version with improvements.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13154093#comment-13154093 ] 

Eldar Agalarov commented on MATH-710:
-------------------------------------

Hi dear Luc! Thank you for message.
I will do as you requested. The reference tests are ready - I'll post them soon, too.
I did not make any changes to the algorithm. I just added the full seeding feature (reference version allows you to have an empty seed, which is not good) and some optimizations, which does not change the logic of the algorithm.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment:     (was: ISAACRandom.java)
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACRandom.java

Fixed version
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java, ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Issue Comment Edited) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13153637#comment-13153637 ] 

Eldar Agalarov edited comment on MATH-710 at 11/20/11 1:32 AM:
---------------------------------------------------------------

Java code of ISAAC CSPRNG. Translated to Java from original C version with improvements.
Note: AbstractRandom superclass is equivalent to BitsStreamGenerator from Common Math library.
                
      was (Author: filosofem):
    Java code of ISAAC CSPRNG. Translated to Java from original C version with improvements.
                  
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Luc Maisonobe (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13153750#comment-13153750 ] 

Luc Maisonobe commented on MATH-710:
------------------------------------

Hi Eldar, thanks for the proposal.
Could you please update the patch so it meets Apache Commons Math checkstyle configuration (Apache header, one statement per line, curly braces around while bodies, javadoc) and add some reference test cases ?
I see you have put an effort on initialization, for example with the golden ratio and shuffling. Does this imply the sequence generated by this implementation is different from the sequence generated by the original algorithm from the same input ? Is it possible to use compatible inputs in your implementation and the original sequence ?
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment:     (was: ISAACRandom.java)
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Description: 
Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 

Algorithm's rewrited (with some improvements) Java code from original C version is attached.


  was:
Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 

Algorithm's rewrited (with some improvements) Java code from original C version:

import java.io.Serializable;

public final class ISAACRandom extends AbstractRandom implements Serializable, Cloneable {

    private static final long serialVersionUID = 7288197941165002400L;

    private static final int SIZE_L = 8;                /* log of size of rsl[] and mem[] */
    private static final int SIZE = 1 << SIZE_L;        /* size of rsl[] and mem[] */
    private static final int H_SIZE = SIZE >> 1;        /* half-size of rsl[] and mem[] */
    private static final int MASK = SIZE - 1 << 2;      /* for pseudorandom lookup */
    private static final int GLD_RATIO = 0x9e3779b9;    /* the golden ratio */
    private static final long SEED_MASK = 0xffffffffL;

    private int[] rsl;                                  /* the results given to the user */
    private int[] mem;                                  /* the internal state */
    private int[] arr;

    private int count;                                  /* count through the results in rsl[] */
    private int a;                                      /* accumulator */
    private int b;                                      /* the last result */
    private int c;                                      /* counter, guarantees cycle is at least 2^^40 */
    private transient int x;
    private transient int i;
    private transient int j;


    public ISAACRandom() {
        this(System.currentTimeMillis());
    }

    public ISAACRandom(long seed) {
        allocArrays();
        setSeed(seed);
    }

    public ISAACRandom(int[] seed) {
        allocArrays();
        setSeed(seed);
    }

    private void allocArrays() {
        rsl = new int[SIZE];
        mem = new int[SIZE];
        arr = new int[8];
    }

    @Override
    public void setSeed(int seed) {
        setSeed(new int[]{seed});
    }

    @Override
    public void setSeed(long seed) {
        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & SEED_MASK)});
    }

    @Override
    public void setSeed(int[] seed) {
        int seedLen = seed.length, rslLen = rsl.length;
        System.arraycopy(seed, 0, rsl, 0, Math.min(seedLen, rslLen));
        if (seedLen < rslLen) {
            for (i = seedLen; i < rslLen; i++) {
                long k = rsl[i - seedLen];
                rsl[i] = (int) (0x6c078965L * (k ^ k >> 30) + i & SEED_MASK);
            }
        }
        initState();
        isaac();
        count = SIZE - 1;
    }

    @Override
    protected int next(int bits) {
        if (count < 0) {
            isaac();
            count = SIZE - 1;
        }
        return rsl[count--] >>> 32 - bits;
    }

    private void isaac() {
        i = 0; j = H_SIZE; b += ++c;
        while (i < H_SIZE) isaac2();
        j = 0;
        while (j < H_SIZE) isaac2();
    }

    private void isaac2() {
        x = mem[i]; a ^= a <<  13; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>>  6; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a <<   2; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>> 16; a += mem[j++]; isaac3();
    }

    private void isaac3() {
        mem[i] = mem[(x & MASK) >> 2] + a + b;
        b = mem[(mem[i] >> SIZE_L & MASK) >> 2] + x;
        rsl[i++] = b;
    }

    private void initState() {
        a = b = c = 0;
        arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = arr[5] = arr[6] = arr[7] = GLD_RATIO;
        for (i = 0; i < 4; i++) shuffle();
        for (i = 0; i < SIZE; i++) mem[i] = rsl[i] = 0;
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += rsl[i];     arr[1] += rsl[i + 1]; arr[2] += rsl[i + 2];
            arr[3] += rsl[i + 3]; arr[4] += rsl[i + 4]; arr[5] += rsl[i + 5];
            arr[6] += rsl[i + 6]; arr[7] += rsl[i + 7];
            shuffle(); setState();
        }
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += mem[i];     arr[1] += mem[i + 1]; arr[2] += mem[i + 2];
            arr[3] += mem[i + 3]; arr[4] += mem[i + 4]; arr[5] += mem[i + 5];
            arr[6] += mem[i + 6]; arr[7] += mem[i + 7];
            shuffle(); setState();
        }
    }

    private void shuffle() {
        arr[0] ^= arr[1] <<  11; arr[3] += arr[0]; arr[1] += arr[2];
        arr[1] ^= arr[2] >>>  2; arr[4] += arr[1]; arr[2] += arr[3];
        arr[2] ^= arr[3] <<   8; arr[5] += arr[2]; arr[3] += arr[4];
        arr[3] ^= arr[4] >>> 16; arr[6] += arr[3]; arr[4] += arr[5];
        arr[4] ^= arr[5] <<  10; arr[7] += arr[4]; arr[5] += arr[6];
        arr[5] ^= arr[6] >>>  4; arr[0] += arr[5]; arr[6] += arr[7];
        arr[6] ^= arr[7] <<   8; arr[1] += arr[6]; arr[7] += arr[0];
        arr[7] ^= arr[0] >>>  9; arr[2] += arr[7]; arr[0] += arr[1];
    }

    private void setState() {
        mem[i] =     arr[0]; mem[i + 1] = arr[1]; mem[i + 2] = arr[2];
        mem[i + 3] = arr[3]; mem[i + 4] = arr[4]; mem[i + 5] = arr[5];
        mem[i + 6] = arr[6]; mem[i + 7] = arr[7];
    }

    @Override
    public ISAACRandom clone() {
        try {
            ISAACRandom cloned = (ISAACRandom) super.clone();
            cloned.rsl = rsl.clone();
            cloned.mem = mem.clone();
            cloned.arr = arr.clone();
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new InternalError(e.getMessage());
        }
    }
}

    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Comment: was deleted

(was: Java code of ISAAC CSPRNG. Translated to Java from original C version with improvements.
Note: AbstractRandom superclass is equivalent to BitsStreamGenerator from Common Math library.)
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Luc Maisonobe (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe resolved MATH-710.
--------------------------------

    Resolution: Fixed

New patch applied as of r1209198.

Thanks again.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java.patch, ISAACTest.java, ISAACTest.java.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13157443#comment-13157443 ] 

Eldar Agalarov commented on MATH-710:
-------------------------------------

Algorithm and reference test is attached.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Luc Maisonobe (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe resolved MATH-710.
--------------------------------

    Resolution: Fixed

Fixed in subversion repository as of r1207554.

Patch applied with minor changes in javadoc (added javadoc for all methods, moved author name to pom file as per Apache Commons policy).

Thanks for the report and for the patch.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13160840#comment-13160840 ] 

Eldar Agalarov commented on MATH-710:
-------------------------------------

Thank you Luc!

SVN patch files with minor changes added.
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java.patch, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACRandom.java
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Description: 
Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 

Rewrited (with some improvements) Java code from original C version is attached.


  was:
Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 

Algorithm's rewrited (with some improvements) Java code from original C version is attached.


    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Description: 
Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 

Algorithm's rewrited (with some improvements) Java code from original C version:

import java.io.Serializable;

public final class ISAACRandom extends AbstractRandom implements Serializable, Cloneable {

    private static final long serialVersionUID = 7288197941165002400L;

    private static final int SIZE_L = 8;                /* log of size of rsl[] and mem[] */
    private static final int SIZE = 1 << SIZE_L;        /* size of rsl[] and mem[] */
    private static final int H_SIZE = SIZE >> 1;        /* half-size of rsl[] and mem[] */
    private static final int MASK = SIZE - 1 << 2;      /* for pseudorandom lookup */
    private static final int GLD_RATIO = 0x9e3779b9;    /* the golden ratio */
    private static final long SEED_MASK = 0xffffffffL;

    private int[] rsl;                                  /* the results given to the user */
    private int[] mem;                                  /* the internal state */
    private int[] arr;

    private int count;                                  /* count through the results in rsl[] */
    private int a;                                      /* accumulator */
    private int b;                                      /* the last result */
    private int c;                                      /* counter, guarantees cycle is at least 2^^40 */
    private transient int x;
    private transient int i;
    private transient int j;


    public ISAACRandom() {
        this(System.currentTimeMillis());
    }

    public ISAACRandom(long seed) {
        allocArrays();
        setSeed(seed);
    }

    public ISAACRandom(int[] seed) {
        allocArrays();
        setSeed(seed);
    }

    private void allocArrays() {
        rsl = new int[SIZE];
        mem = new int[SIZE];
        arr = new int[8];
    }

    @Override
    public void setSeed(int seed) {
        setSeed(new int[]{seed});
    }

    @Override
    public void setSeed(long seed) {
        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & SEED_MASK)});
    }

    @Override
    public void setSeed(int[] seed) {
        int seedLen = seed.length, rslLen = rsl.length;
        System.arraycopy(seed, 0, rsl, 0, Math.min(seedLen, rslLen));
        if (seedLen < rslLen) {
            for (i = seedLen; i < rslLen; i++) {
                long k = rsl[i - seedLen];
                rsl[i] = (int) (0x6c078965L * (k ^ k >> 30) + i & SEED_MASK);
            }
        }
        initState();
        isaac();
        count = SIZE - 1;
    }

    @Override
    protected int next(int bits) {
        if (count < 0) {
            isaac();
            count = SIZE - 1;
        }
        return rsl[count--] >>> 32 - bits;
    }

    private void isaac() {
        i = 0; j = H_SIZE; b += ++c;
        while (i < H_SIZE) isaac2();
        j = 0;
        while (j < H_SIZE) isaac2();
    }

    private void isaac2() {
        x = mem[i]; a ^= a <<  13; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>>  6; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a <<   2; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>> 16; a += mem[j++]; isaac3();
    }

    private void isaac3() {
        mem[i] = mem[(x & MASK) >> 2] + a + b;
        b = mem[(mem[i] >> SIZE_L & MASK) >> 2] + x;
        rsl[i++] = b;
    }

    private void initState() {
        a = b = c = 0;
        arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = arr[5] = arr[6] = arr[7] = GLD_RATIO;
        for (i = 0; i < 4; i++) shuffle();
        for (i = 0; i < SIZE; i++) mem[i] = rsl[i] = 0;
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += rsl[i];     arr[1] += rsl[i + 1]; arr[2] += rsl[i + 2];
            arr[3] += rsl[i + 3]; arr[4] += rsl[i + 4]; arr[5] += rsl[i + 5];
            arr[6] += rsl[i + 6]; arr[7] += rsl[i + 7];
            shuffle(); setState();
        }
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += mem[i];     arr[1] += mem[i + 1]; arr[2] += mem[i + 2];
            arr[3] += mem[i + 3]; arr[4] += mem[i + 4]; arr[5] += mem[i + 5];
            arr[6] += mem[i + 6]; arr[7] += mem[i + 7];
            shuffle(); setState();
        }
    }

    private void shuffle() {
        arr[0] ^= arr[1] <<  11; arr[3] += arr[0]; arr[1] += arr[2];
        arr[1] ^= arr[2] >>>  2; arr[4] += arr[1]; arr[2] += arr[3];
        arr[2] ^= arr[3] <<   8; arr[5] += arr[2]; arr[3] += arr[4];
        arr[3] ^= arr[4] >>> 16; arr[6] += arr[3]; arr[4] += arr[5];
        arr[4] ^= arr[5] <<  10; arr[7] += arr[4]; arr[5] += arr[6];
        arr[5] ^= arr[6] >>>  4; arr[0] += arr[5]; arr[6] += arr[7];
        arr[6] ^= arr[7] <<   8; arr[1] += arr[6]; arr[7] += arr[0];
        arr[7] ^= arr[0] >>>  9; arr[2] += arr[7]; arr[0] += arr[1];
    }

    private void setState() {
        mem[i] =     arr[0]; mem[i + 1] = arr[1]; mem[i + 2] = arr[2];
        mem[i + 3] = arr[3]; mem[i + 4] = arr[4]; mem[i + 5] = arr[5];
        mem[i + 6] = arr[6]; mem[i + 7] = arr[7];
    }

    @Override
    public ISAACRandom clone() {
        try {
            ISAACRandom cloned = (ISAACRandom) super.clone();
            cloned.rsl = rsl.clone();
            cloned.mem = mem.clone();
            cloned.arr = arr.clone();
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new InternalError(e.getMessage());
        }
    }
}

  was:
Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG. Java code is below:

import java.io.Serializable;

public final class ISAACRandom extends AbstractRandom implements Serializable, Cloneable {

    private static final long serialVersionUID = 7288197941165002400L;

    private static final int SIZE_L = 8;                /* log of size of rsl[] and mem[] */
    private static final int SIZE = 1 << SIZE_L;        /* size of rsl[] and mem[] */
    private static final int H_SIZE = SIZE >> 1;        /* half-size of rsl[] and mem[] */
    private static final int MASK = SIZE - 1 << 2;      /* for pseudorandom lookup */
    private static final int GLD_RATIO = 0x9e3779b9;    /* the golden ratio */
    private static final long SEED_MASK = 0xffffffffL;

    private int[] rsl;                                  /* the results given to the user */
    private int[] mem;                                  /* the internal state */
    private int[] arr;

    private int count;                                  /* count through the results in rsl[] */
    private int a;                                      /* accumulator */
    private int b;                                      /* the last result */
    private int c;                                      /* counter, guarantees cycle is at least 2^^40 */
    private transient int x;
    private transient int i;
    private transient int j;


    public ISAACRandom() {
        this(System.currentTimeMillis());
    }

    public ISAACRandom(long seed) {
        allocArrays();
        setSeed(seed);
    }

    public ISAACRandom(int[] seed) {
        allocArrays();
        setSeed(seed);
    }

    private void allocArrays() {
        rsl = new int[SIZE];
        mem = new int[SIZE];
        arr = new int[8];
    }

    @Override
    public void setSeed(int seed) {
        setSeed(new int[]{seed});
    }

    @Override
    public void setSeed(long seed) {
        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & SEED_MASK)});
    }

    @Override
    public void setSeed(int[] seed) {
        int seedLen = seed.length, rslLen = rsl.length;
        System.arraycopy(seed, 0, rsl, 0, Math.min(seedLen, rslLen));
        if (seedLen < rslLen) {
            for (i = seedLen; i < rslLen; i++) {
                long k = rsl[i - seedLen];
                rsl[i] = (int) (0x6c078965L * (k ^ k >> 30) + i & SEED_MASK);
            }
        }
        initState();
        isaac();
        count = SIZE - 1;
    }

    @Override
    protected int next(int bits) {
        if (count < 0) {
            isaac();
            count = SIZE - 1;
        }
        return rsl[count--] >>> 32 - bits;
    }

    private void isaac() {
        i = 0; j = H_SIZE; b += ++c;
        while (i < H_SIZE) isaac2();
        j = 0;
        while (j < H_SIZE) isaac2();
    }

    private void isaac2() {
        x = mem[i]; a ^= a <<  13; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>>  6; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a <<   2; a += mem[j++]; isaac3();
        x = mem[i]; a ^= a >>> 16; a += mem[j++]; isaac3();
    }

    private void isaac3() {
        mem[i] = mem[(x & MASK) >> 2] + a + b;
        b = mem[(mem[i] >> SIZE_L & MASK) >> 2] + x;
        rsl[i++] = b;
    }

    private void initState() {
        a = b = c = 0;
        arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = arr[5] = arr[6] = arr[7] = GLD_RATIO;
        for (i = 0; i < 4; i++) shuffle();
        for (i = 0; i < SIZE; i++) mem[i] = rsl[i] = 0;
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += rsl[i];     arr[1] += rsl[i + 1]; arr[2] += rsl[i + 2];
            arr[3] += rsl[i + 3]; arr[4] += rsl[i + 4]; arr[5] += rsl[i + 5];
            arr[6] += rsl[i + 6]; arr[7] += rsl[i + 7];
            shuffle(); setState();
        }
        for (i = 0; i < SIZE; i += 8) {
            arr[0] += mem[i];     arr[1] += mem[i + 1]; arr[2] += mem[i + 2];
            arr[3] += mem[i + 3]; arr[4] += mem[i + 4]; arr[5] += mem[i + 5];
            arr[6] += mem[i + 6]; arr[7] += mem[i + 7];
            shuffle(); setState();
        }
    }

    private void shuffle() {
        arr[0] ^= arr[1] <<  11; arr[3] += arr[0]; arr[1] += arr[2];
        arr[1] ^= arr[2] >>>  2; arr[4] += arr[1]; arr[2] += arr[3];
        arr[2] ^= arr[3] <<   8; arr[5] += arr[2]; arr[3] += arr[4];
        arr[3] ^= arr[4] >>> 16; arr[6] += arr[3]; arr[4] += arr[5];
        arr[4] ^= arr[5] <<  10; arr[7] += arr[4]; arr[5] += arr[6];
        arr[5] ^= arr[6] >>>  4; arr[0] += arr[5]; arr[6] += arr[7];
        arr[6] ^= arr[7] <<   8; arr[1] += arr[6]; arr[7] += arr[0];
        arr[7] ^= arr[0] >>>  9; arr[2] += arr[7]; arr[0] += arr[1];
    }

    private void setState() {
        mem[i] =     arr[0]; mem[i + 1] = arr[1]; mem[i + 2] = arr[2];
        mem[i + 3] = arr[3]; mem[i + 4] = arr[4]; mem[i + 5] = arr[5];
        mem[i + 6] = arr[6]; mem[i + 7] = arr[7];
    }

    @Override
    public ISAACRandom clone() {
        try {
            ISAACRandom cloned = (ISAACRandom) super.clone();
            cloned.rsl = rsl.clone();
            cloned.mem = mem.clone();
            cloned.arr = arr.clone();
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new InternalError(e.getMessage());
        }
    }
}

    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version:
> import java.io.Serializable;
> public final class ISAACRandom extends AbstractRandom implements Serializable, Cloneable {
>     private static final long serialVersionUID = 7288197941165002400L;
>     private static final int SIZE_L = 8;                /* log of size of rsl[] and mem[] */
>     private static final int SIZE = 1 << SIZE_L;        /* size of rsl[] and mem[] */
>     private static final int H_SIZE = SIZE >> 1;        /* half-size of rsl[] and mem[] */
>     private static final int MASK = SIZE - 1 << 2;      /* for pseudorandom lookup */
>     private static final int GLD_RATIO = 0x9e3779b9;    /* the golden ratio */
>     private static final long SEED_MASK = 0xffffffffL;
>     private int[] rsl;                                  /* the results given to the user */
>     private int[] mem;                                  /* the internal state */
>     private int[] arr;
>     private int count;                                  /* count through the results in rsl[] */
>     private int a;                                      /* accumulator */
>     private int b;                                      /* the last result */
>     private int c;                                      /* counter, guarantees cycle is at least 2^^40 */
>     private transient int x;
>     private transient int i;
>     private transient int j;
>     public ISAACRandom() {
>         this(System.currentTimeMillis());
>     }
>     public ISAACRandom(long seed) {
>         allocArrays();
>         setSeed(seed);
>     }
>     public ISAACRandom(int[] seed) {
>         allocArrays();
>         setSeed(seed);
>     }
>     private void allocArrays() {
>         rsl = new int[SIZE];
>         mem = new int[SIZE];
>         arr = new int[8];
>     }
>     @Override
>     public void setSeed(int seed) {
>         setSeed(new int[]{seed});
>     }
>     @Override
>     public void setSeed(long seed) {
>         setSeed(new int[]{(int) (seed >>> 32), (int) (seed & SEED_MASK)});
>     }
>     @Override
>     public void setSeed(int[] seed) {
>         int seedLen = seed.length, rslLen = rsl.length;
>         System.arraycopy(seed, 0, rsl, 0, Math.min(seedLen, rslLen));
>         if (seedLen < rslLen) {
>             for (i = seedLen; i < rslLen; i++) {
>                 long k = rsl[i - seedLen];
>                 rsl[i] = (int) (0x6c078965L * (k ^ k >> 30) + i & SEED_MASK);
>             }
>         }
>         initState();
>         isaac();
>         count = SIZE - 1;
>     }
>     @Override
>     protected int next(int bits) {
>         if (count < 0) {
>             isaac();
>             count = SIZE - 1;
>         }
>         return rsl[count--] >>> 32 - bits;
>     }
>     private void isaac() {
>         i = 0; j = H_SIZE; b += ++c;
>         while (i < H_SIZE) isaac2();
>         j = 0;
>         while (j < H_SIZE) isaac2();
>     }
>     private void isaac2() {
>         x = mem[i]; a ^= a <<  13; a += mem[j++]; isaac3();
>         x = mem[i]; a ^= a >>>  6; a += mem[j++]; isaac3();
>         x = mem[i]; a ^= a <<   2; a += mem[j++]; isaac3();
>         x = mem[i]; a ^= a >>> 16; a += mem[j++]; isaac3();
>     }
>     private void isaac3() {
>         mem[i] = mem[(x & MASK) >> 2] + a + b;
>         b = mem[(mem[i] >> SIZE_L & MASK) >> 2] + x;
>         rsl[i++] = b;
>     }
>     private void initState() {
>         a = b = c = 0;
>         arr[0] = arr[1] = arr[2] = arr[3] = arr[4] = arr[5] = arr[6] = arr[7] = GLD_RATIO;
>         for (i = 0; i < 4; i++) shuffle();
>         for (i = 0; i < SIZE; i++) mem[i] = rsl[i] = 0;
>         for (i = 0; i < SIZE; i += 8) {
>             arr[0] += rsl[i];     arr[1] += rsl[i + 1]; arr[2] += rsl[i + 2];
>             arr[3] += rsl[i + 3]; arr[4] += rsl[i + 4]; arr[5] += rsl[i + 5];
>             arr[6] += rsl[i + 6]; arr[7] += rsl[i + 7];
>             shuffle(); setState();
>         }
>         for (i = 0; i < SIZE; i += 8) {
>             arr[0] += mem[i];     arr[1] += mem[i + 1]; arr[2] += mem[i + 2];
>             arr[3] += mem[i + 3]; arr[4] += mem[i + 4]; arr[5] += mem[i + 5];
>             arr[6] += mem[i + 6]; arr[7] += mem[i + 7];
>             shuffle(); setState();
>         }
>     }
>     private void shuffle() {
>         arr[0] ^= arr[1] <<  11; arr[3] += arr[0]; arr[1] += arr[2];
>         arr[1] ^= arr[2] >>>  2; arr[4] += arr[1]; arr[2] += arr[3];
>         arr[2] ^= arr[3] <<   8; arr[5] += arr[2]; arr[3] += arr[4];
>         arr[3] ^= arr[4] >>> 16; arr[6] += arr[3]; arr[4] += arr[5];
>         arr[4] ^= arr[5] <<  10; arr[7] += arr[4]; arr[5] += arr[6];
>         arr[5] ^= arr[6] >>>  4; arr[0] += arr[5]; arr[6] += arr[7];
>         arr[6] ^= arr[7] <<   8; arr[1] += arr[6]; arr[7] += arr[0];
>         arr[7] ^= arr[0] >>>  9; arr[2] += arr[7]; arr[0] += arr[1];
>     }
>     private void setState() {
>         mem[i] =     arr[0]; mem[i + 1] = arr[1]; mem[i + 2] = arr[2];
>         mem[i + 3] = arr[3]; mem[i + 4] = arr[4]; mem[i + 5] = arr[5];
>         mem[i + 6] = arr[6]; mem[i + 7] = arr[7];
>     }
>     @Override
>     public ISAACRandom clone() {
>         try {
>             ISAACRandom cloned = (ISAACRandom) super.clone();
>             cloned.rsl = rsl.clone();
>             cloned.mem = mem.clone();
>             cloned.arr = arr.clone();
>             return cloned;
>         } catch (CloneNotSupportedException e) {
>             throw new InternalError(e.getMessage());
>         }
>     }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Issue Comment Edited) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13153647#comment-13153647 ] 

Eldar Agalarov edited comment on MATH-710 at 11/20/11 2:53 AM:
---------------------------------------------------------------

Java code of ISAAC CSPRNG. Translated to Java from original C version with improvements.
                
      was (Author: filosofem):
    Fixed version
                  
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Common Math library support for ISAAC random number generator. This is a free and open-source PRNG (http://burtleburtle.net/bob/rand/isaacafa.html). 
> Algorithm's rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACTest.java.patch
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java.patch, ISAACTest.java, ISAACTest.java.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACTest.java
                ISAACRandom.java
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>         Attachments: ISAACRandom.java, ISAACRandom.java, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Reopened] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Reopened) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov reopened MATH-710:
---------------------------------


Patch files added with minor changes
                
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java.patch, ISAACTest.java, ISAACTest.java.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (MATH-710) Add support for fast cryptographically secure pseudorandom number generator ISAAC

Posted by "Eldar Agalarov (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eldar Agalarov updated MATH-710:
--------------------------------

    Attachment: ISAACRandom.java.patch
    
> Add support for fast cryptographically secure pseudorandom number generator ISAAC
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-710
>                 URL: https://issues.apache.org/jira/browse/MATH-710
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 2.2
>            Reporter: Eldar Agalarov
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: ISAACRandom.java, ISAACRandom.java.patch, ISAACTest.java
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Dear developers, please add to Commons Math library support for ISAAC random number generator. This is a free and open-source CSPRNG (see at http://burtleburtle.net/bob/rand/isaacafa.html). 
> Rewrited (with some improvements) Java code from original C version is attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira