nomemory/mockneat

Incorrect documentation around secure random seeding

Jazzepi opened this issue · 0 comments

For particular use-cases, new MockNeat instances can be created by invoking the directly the public constructor. For example, if we want to create a secure MockNeat object with 123l as the seed:

Long seed = 123l;
// Note: RandomType.SECURE is the only type that supports seeding.
MockNeat mock = new MockNeat(RandomType.SECURE, seed);
It’s highly recommended to avoid creating multiple MockNeat instances. It’s better to stick with one instance per-project.

Two problems.

  1. This isn't correct. // Note: RandomType.SECURE is the only type that supports seeding.
long hashBasis = 99823981L;
System.out.println(new MockNeat(RandomType.OLD, hashBasis).countries().names().get());
System.out.println(new MockNeat(RandomType.OLD, hashBasis).countries().names().get());
System.out.println(new MockNeat(RandomType.OLD, hashBasis).countries().names().get());
System.out.println(new MockNeat(RandomType.OLD, hashBasis).countries().names().get());

Prints out

Iceland
Iceland
Iceland
Iceland

  1. You cannot successfully seed a SecureRandom instance. You can call setSeed() on it, but all that does is mix your seed in with the secure random's one. From my perspective I need the seed to be the same because I want random data, but I want random stable data in my tests. For this reason I would propose changing the docs to show that RandomType.OLD can be used if you want random mocked data that is stable.