# Library RandomXT

Discussion in 'Resources' started by Gorbit99, Dec 28, 2015.

Not open for further replies.
1. Offline

### Gorbit99

When I was programming, I was running into some problems with Random. Sometimes it didn't have things I needed and when I made them myself, they took an awful lot of space to make, so I created this library.

What it does:
It has some features that the original Random class doesn't, for example bellcurves and dice throws.

Methods:
RandomXT.bellCurve(int steepness, int limit);
this method gives you a weighted value between 0(inclusive) and "limit"(exclusive).

steepness: The steepness of the bell curve. Value must be at least 2.
RandomXT.cappedDecimal(int decimalCount, float limit);
Gives you a random float with maximum "decimalCount" decimals.

limit: Maximum value of random(exclusive).
RandomXT.diceThrow(int sides, int dices);
returns a list of ints with "dices" ints inside with a minimum value of 1 (inclusive) and maximum of "sides" (inclusive)

Code:
Code:
```package libs;

import java.util.ArrayList;
import java.util.List;

public class RandomXT {

public static int bellCurve(int steepness, int limit) {
int sum = 0;
for (int x = 0; x < steepness; x++) {
}
int rand = sum / steepness;
return rand;
}

public static float cappedDecimal(int decimalCount, float limit) {
float rand = ThreadLocalRandom.current().nextInt((int) Math.round(limit * Math.pow(10, decimalCount)));
rand /= Math.pow(10, decimalCount);
return rand;
}

public List<Integer> diceThrow(int sides, int dices) {
List<Integer> thrown = new ArrayList<Integer>();
for (int x = 0; x < dices; x++) {
}
return thrown;
}

}```

Write down your suggestions down below!

Last edited: Dec 29, 2015
#1
2. Offline

### teej107

Use ThreadLocalRandom or create a single static Random constant.

#2
Mrs. bwfctower likes this.
3. Offline

### Gorbit99

#3
teej107 likes this.
4. Offline

### KingFaris11

Can you explain this?

Normally I'd have a Utilities class and have:
Code:
```private static Random random = new Random();

public static Random getRandom() {
return random;
}
```

#4
5. Offline

### mcdorli

The first article here

#5
teej107 and KingFaris11 like this.
6. Offline

### Gorbit99

@teej107 BTW, creating a single static Random wouldn't be as easy, because I don't plan on having a constructor

#6
7. Offline

### teej107

@Gorbit99 You don't need a constructor to declare and assign values to static fields.
Code:
`private static final Random RANDOM = new Random();`
ThreadLocalRandom is a good one to use though.

#7
Mrs. bwfctower and Gorbit99 like this.