random number with LuaLatex not updating

Added by Julien GIBELIN 10 days ago

Dear all,

I started generating MCQ based a latex file.

The source file contains random numbers generated with lualatex.

I was hoping that each subject will have different numbers but this is not the case, the numbers are the same for every copy (not only in the answers but also in the questions).

Did I miss some configuration in AMC (or in lualatex)? I assumed that a another compilation is done for each copy.

Did anybody experience something similar?

Thank you in advance
Best regards


Replies (7)

RE: random number with LuaLatex not updating - Added by Frédéric Bréal 8 days ago

Google traduction (et mes souvenirs de collège).
Did you use the seed generator math.randomseed() ?
https://stackoverflow.com/questions/35455489/difference-between-math-random-and-math-randomseed-in-lua

RE: random number with LuaLatex not updating - Added by Julien GIBELIN 8 days ago

Thank you for your answer

Yes and I fixed it to be sure that I found the same values.
Thinking of it is a little bit stupid because it will note generate different values at each compilation...

Even if I remove it the "random" values are still the same

So somehow the question remains... plus another now: how to generate different value for each copy and ensure that these value are always the same for a given copy?

Thank you in advance
Regards

Traduction en français:
Oui j'utilise math.randomseed(2048) car je voulais m'assurer qu'un sujet donné (1, 2, 3...) avait toujours les mêmes valeurs.
A la réflexion c'est un peu bête comme approche car en principe à chaque compilation je devrais avoir la même suite de nombre.
Ceci dit pour tester si j'enlève math.randomseed(2048) j'obtiens toujours les mêmes valeurs pour tous les sujets...
Ce qui ne répond pas encore à ma question mais surtout en pose une autre : comment faire pour les nombres générés soient toujours les mêmes pour un numéro de copie donnée et que ce nombre soit différent pour chaque copie ? L'astuce pourrait être de mettre une graine qui dépend du numéro de sujet...

RE: random number with LuaLatex not updating - Added by Frédéric Bréal 8 days ago

Ceci dit pour tester si j'enlève math.randomseed(2048) j'obtiens toujours les mêmes valeurs pour tous les sujets

Les mêmes valeurs mais quand même différentes avec ou sans math.randomseed(2048) ?

Essayez ceci ou

\exemplaire{x}{
math.randomseed(\AMCStudentNumber)
…
}

Deeple (pour changer)

Even if I remove it the "random" values are still the same

The same values, but different with or without math.randomseed(2048)?
Try this or

\onecopy{x}{
math.randomseed(\AMCStudentNumber)
…
}

RE: random number with LuaLatex not updating - Added by Julien GIBELIN 8 days ago

I tried what you suggested

\directlua{math.randomseed (\AMCStudentNumber)}

does not work, always the same value for each subject

_ j'ai essayé ce que vous proposez \directlua{math.randomseed (\AMCStudentNumber)} ça ne marche pas j'ai toujours les mêmes valeurs à chaque copie_

RE: random number with LuaLatex not updating - Added by Julien GIBELIN 8 days ago

I also checked if \AMCStudentNumber is understood: yes, I can fill a variable with that value.

j'ai aussi vérifié si \AMCStudentNumber est bien compris, oui je peux remplir une variable lua avec

RE: random number with LuaLatex not updating - Added by Julien GIBELIN 8 days ago

I think I know where the problem lies: my definition are outside onecopy

je pense que je sais où est mon problème : mes définitions sont en dehors de exemplaire, je vérifie

RE: random number with LuaLatex not updating - Added by Julien GIBELIN 8 days ago

Ok I solved the problem: all the variables of my problems are defined inside a luacode environment at the beginning of my latex file.
For a reason probably due to the philosophy of AMC this part is not recall for each copy (I am used the GUI).
In order to force the recalculation of the value I embedded these definition in a function, which is called at the beginning of onecopy macro after I run
\directlua{math.randomseed (\AMCStudentNumber)}
It works.
Thank you for your help

Ok j'ai résolu le problème : toutes les variables de mes problèmes sont définies à l'intérieur d'un environnement luacode au début de mon fichier latex.
Pour une raison probablement due à la philosophie d'AMC cette partie n'est pas rappelée à chaque copie (notez que j'utilise l'interface graphique).
Afin de forcer le recalcul de la valeur, j'ai incorporé ces définitions dans une fonction, qui est appelée au début de la macro onecopy après avoir exécuté
\directlua{math.randomseed (\AMCStudentNumber)}
Cela fonctionne.
Je vous remercie pour votre aide.

(1-7/7)