Jump to content

grandom() deprecated?


avid

Recommended Posts

I seem to remember it was deprecated because it wasn't functioning correctly; the API now only supports linear random. That being said, it's not too hard to come up with your own equivalent using https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextGaussian()

Make sure to take into account far-edge generations though!

Apa

  • Like 1
Link to comment
Share on other sites

I deprecated it because it doesn't create a normal distribution, it only creates the positive half of the bell curve. My official solution was/is the following:

 

 public static int gRandom(int mean, double stdDeviation)
            throws IllegalArgumentException {
        if (mean < 0)
            throw new IllegalArgumentException("Mean can't be lower than 0!");
        double max = stdDeviation * 3;
        int result;
        do {
            result = Math.toIntExact(Math.round(random.nextGaussian() * stdDeviation + mean));
        } while (Math.abs(result - mean) > max);
        return result;
    }

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...