random - Is there any guarantee that the algorithm behind java.util.Collections.shuffle() remains unchanged in future Java releases? -
is following program guaranteed produce list same contents , ordering in future java releases?
import java.util.arraylist; import java.util.arrays; import java.util.collections; import java.util.list; import java.util.random; public class test { public static void main(string[] args) { list<string> list = new arraylist<>(arrays.aslist("a", "b", "c", "d")); collections.shuffle(list, new random(42)); } }
the javadoc of java.util.random
class guarantees return same random numbers if intialized same seed in future java releases.
but there guarantees regarding algorithm behind java.util.collections.shuffle()
utility function? javadoc utility function not this.
i need guarantee, because want sure persisted data not useless future java release.
there no explicit guarantee, say.
on other hand, existence of separate collections.shuffle(list,random)
suggest intention method return same order when invoked random
in identical state. (this useful create repeatable tests example.)
so it's bit of grey area.
but if core functionality depends on , want absolutely sure, can implement fisher-yates algorithm (or rather, more efficient durstenfeld algorithm) yourself, it's simple. it's simple it's not worth taking (probably small) risk collections.shuffle()
change in future.
Comments
Post a Comment