Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException from Random.nextInt #20

Closed
MiroLehteva opened this issue May 25, 2015 · 1 comment
Closed

IllegalArgumentException from Random.nextInt #20

MiroLehteva opened this issue May 25, 2015 · 1 comment

Comments

@MiroLehteva
Copy link

Hi,

I've implemented a particle animation using this library, but I keep getting this exceptions from time to time. Here is the stacktrace from the exception I got from the exception.

E/AndroidRuntime﹕ FATAL EXCEPTION: Timer-28
java.lang.IllegalArgumentException
at java.util.Random.nextInt(Random.java:187)
at com.plattysoft.leonids.ParticleSystem.getFromRange(ParticleSystem.java:536)
at com.plattysoft.leonids.ParticleSystem.activateParticle(ParticleSystem.java:524)
at com.plattysoft.leonids.ParticleSystem.onUpdate(ParticleSystem.java:544)
at com.plattysoft.leonids.ParticleSystem.access$1(ParticleSystem.java:539)
at com.plattysoft.leonids.ParticleSystem$1.run(ParticleSystem.java:363)
at java.util.Timer$TimerImpl.run(Timer.java:284)

I did search trough Random class and I found only one IllegalArgumentException from the whole class in the method nextInt(int n).

   /**
     * Returns a pseudo-random uniformly distributed {@code int}
     * in the half-open range [0, n).
     */
    public int nextInt(int n) {
        if (n <= 0) {
           throw new IllegalArgumentException("n <= 0: " + n);
        }
        if ((n & -n) == n) {
            return (int) ((n * (long) next(31)) >> 31);
        }
        int bits, val;
        do {
            bits = next(31);
            val = bits % n;
        } while (bits - val + (n - 1) < 0);
        return val;
    }
@plattysoft
Copy link
Owner

The range is always from the smaller number to the larger one, and both numbers must be positive.
The direction is configured by using the angle.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants