luatex for random numbers
![](https://secure.gravatar.com/avatar/30ef4fea8acc9a4c7a392675260cfcb9.jpg?s=120&d=mm&r=g)
Hello friends, I have a small but urgent question. How to call luatex commands in the document? (I heard there were some recent changes.) More specifically, how to generate integer random numbers in given range? I'm preparing a quiz on numbering systems for my students on tomorrow, so your fast help would be greatly appreciated! :) Best regards, Vyatcheslav Yatskovsky
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
Vyatcheslav Yatskovsky wrote:
Hello friends,
I have a small but urgent question.
How to call luatex commands in the document? (I heard there were some recent changes.) More specifically, how to generate integer random numbers in given range? I'm preparing a quiz on numbering systems for my students on tomorrow, so your fast help would be greatly appreciated! :)
\startluacode \stopluacode \ctxlua{...} whatever you like tex.sprint(someresult) pipes back into tex ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/30ef4fea8acc9a4c7a392675260cfcb9.jpg?s=120&d=mm&r=g)
Hello Hans, Thanks. Is there any way to print a number in hex or bin form? (Either using lua or tex facilities?) I already know how to generate random integer numbers, \ctxlua{tex.print(math.random(30,60)) ;} now I need to represent them as binary or hexadecimal. -- Best regards, Vyatcheslav Yatskovsky
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
Vyatcheslav Yatskovsky wrote:
Hello Hans,
Thanks. Is there any way to print a number in hex or bin form? (Either using lua or tex facilities?) I already know how to generate random integer numbers, \ctxlua{tex.print(math.random(30,60)) ;} now I need to represent them as binary or hexadecimal.
you can use string.format if you wanna use lua seriously, it makes sense to buy the book ... easy reading, very complete and inexpensive Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Vyatcheslav Yatskovsky