0

Lets have the following sample:

import java.util.*; 

public class MyClass {
    public static void main(String args[]) {
      Random rnd = new Random();
      
      rnd.setSeed(45);
      float v = rnd.nextFloat();
      v = rnd.nextFloat();
      v = rnd.nextFloat();
      v = rnd.nextFloat();
      v = rnd.nextFloat();
      
      float expectedNext = rnd.nextFloat();

      float nextSeend = ???;

      rnd.setSeed(nextSeend);
      v = rnd.nextFloat();

      System.out.println("expected=" + expectedNext + " result=" + v);
    }
}

I'm looking for a way to have: expectedNext = v

It means that I'm looking to continue the same sequence (without replaying the 5x nextFloat).

Eric J.
  • 147,927
  • 63
  • 340
  • 553
ClubberLang
  • 1,624
  • 3
  • 21
  • 45
  • Does this answer your question? [How do I get the seed from a Random in Java?](https://stackoverflow.com/questions/6001368/how-do-i-get-the-seed-from-a-random-in-java) – Peter O. Jul 16 '20 at 21:12
  • For .NET see: https://stackoverflow.com/questions/36030374/how-can-i-get-the-seed-from-a-random-already-created – Peter O. Jul 16 '20 at 21:15
  • [Another one](https://stackoverflow.com/questions/19512210/how-to-save-the-state-of-a-random-generator-in-c).... – Idle_Mind Jul 16 '20 at 21:16
  • Thanks, but unfortunately it does not help. The RND occur on a backend, so I can serialize/save a state etc... (I have no control on the back end, it is ElasticSearch). I need a solution based on pure math by example, like quasi-random + specific seed. – ClubberLang Jul 17 '20 at 06:24

0 Answers0