mercredi 18 juillet 2018

Length of an infinite IntStream?

I have created an randomIntStream by this:

 final static PrimitiveIterator.OfInt startValue = new Random().ints(0, 60).iterator();

The documentation says this stream is actually endless.

I want to understand what happens there in the backround.

ints(0,60) is generating an infinite stream of integers. If this is infinite, why my machine is not leaking any memory?

I wonder, how many numbers are actually really generated and if this implemenentation can cause an error at the point where the stream still ends? Or will this stream constantly filled with new integers on the fly and it really never ends therefore?

And if I already ask this question, what is the best practise right now to generate random numbers nowadays?




Aucun commentaire:

Enregistrer un commentaire