Decaf: Random
-------------

                 Key: AMQCPP-125
                 URL: https://issues.apache.org/activemq/browse/AMQCPP-125
             Project: ActiveMQ C++ Client
          Issue Type: New Feature
    Affects Versions: 2.2
            Reporter: Albert Strasheim
            Assignee: Nathan Mittler
            Priority: Minor
         Attachments: Randomv1.diff

Attached is a patch that implements a Random class that works the same as 
java.util.Random. This code can probably go into Decaf. The patch puts it in 
activemq/util for now.

I adapted the code from Harmony's implementation of Random:

http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Random.java?revision=530264&view=markup

I couldn't find a test for java.util.Random in the Harmony sources (just took a 
quick look), so I used the values from the Mauve test:

http://sources.redhat.com/cgi-bin/cvsweb.cgi/mauve/gnu/testlet/java/util/Random/basic.java?rev=1.5&content-type=text/x-cvsweb-markup&cvsroot=mauve

The Mauve tests are licensed under the GPL. Does using a few values from this 
test cause problems as far as licensing of this new code goes? Hopefully not.

The port to C++ was more or less straightforward. There were three main issues:

1. C++ doesn't have >>>. If I understand >>> correctly, in C++ it's equivalent 
to doing >> on an unsigned type.

2. You can't shift more than 31 places at a time in a portable manner. This is 
because at least the Intel shift instructions only look at the bottom 5 bits of 
the register that tells it how far to shift. As far as I know, the easiest 
solution is just to shift multiple times.

3. Some java.util.Random methods are synchronized. I haven't included this 
functionality in the first version of the patch. It should be easy to add.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to