MCPcopy Create free account
hub / github.com/VolmitSoftware/Adapt / RNG

Class RNG

src/main/java/com/volmit/adapt/util/RNG.java:25–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23import java.util.UUID;
24
25public class RNG extends Random {
26 public static final RNG r = new RNG();
27 private static final char[] CHARGEN = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=!@#$%^&*()_+`~[];',./<>?:\\\"{}|\\\\".toCharArray();
28 private static final long serialVersionUID = 5222938581174415179L;
29 private final long sx;
30
31 public RNG() {
32 super();
33 sx = 0;
34 }
35
36 public RNG(long seed) {
37 super(seed);
38 this.sx = seed;
39 }
40
41 /**
42 * Creates a seed (long) from the hash of the seed string
43 *
44 * @param seed the seed (string)
45 */
46 public RNG(String seed) {
47 this(UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getLeastSignificantBits() + UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits() + (seed.length() * 32564));
48 }
49
50 public RNG nextParallelRNG(int signature) {
51 return new RNG(sx + signature);
52 }
53
54 public RNG nextParallelRNG(long signature) {
55 return new RNG(sx + signature);
56 }
57
58 public RNG nextRNG() {
59 return new RNG(nextLong());
60 }
61
62 public String s(int length) {
63 StringBuilder sb = new StringBuilder();
64
65 for (int i = 0; i < length; i++) {
66 sb.append(c());
67 }
68
69 return sb.toString();
70 }
71
72 public char c() {
73 return CHARGEN[i(CHARGEN.length - 1)];
74 }
75
76 /**
77 * Pick a random enum
78 *
79 * @param t the enum class
80 * @return the enum
81 */
82 public <T> T e(Class<T> t) {

Callers

nothing calls this directly

Calls 1

toCharArrayMethod · 0.80

Tested by

no test coverage detected