Can I Reset Random to avoid same Sequence

Jan Burse, created Nov 07. 2013 alex, Nov 06. 2013, 17:22 wrote: remark: random fonction générate always the same séquence of number until exit prolog. Is there a function to reset this function ?

Comments

Re: Can I Reset Random to avoid same Sequence

Jan Burse, created Nov 07. 2013 Hi, Yes there are issues with the current random generate of Jekejeke Prolog. First of all we do not have an API to influence the random generator. So the following predicates are missing: randomize/0: Choose a random seed. set_seed/1: Set the random seed. get_seed/1: Retrieve the random seed. I will try to provide these functions in a next release. Second the random predicate/function uses the java.util.Random class. An instance is initially created for a knowledge base when Jekejeke Prolog is started. Unfortunately the implementation of the constructor has changed. So in the old times currentTimeMillis() was used as a seed in the constructor, and thus we got initial randomization. Newer implementations use nanoTime(). Unfortunately nanoTime() often measures elapsed time since startup, so it can happen, that the seed gets always the same value. Although I think it is unlickely. I will also try to change the initial construction. Hope this helps. Bye