Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Thierry Horsin via ntg-context
Hi again,
Many thanks to Hans and Hans and Henri.

The solution (going to low level) provided by Hans works fine.
Best
Thierry


Le Monday 23 Aug 2021 à 17:13:00 (+0200), Hans Hagen a écrit :
> On 8/23/2021 4:46 PM, Thierry Horsin via ntg-context wrote:
> > Hi everybody.
> > 
> > I wonder how does math.random() work in context. I found that this subject 
> > was discussed more than ten years ago by Otared and Taco and Thomas. It is 
> > clear to me how to obtain new results upon typesetting the same file by 
> > changing the value of math.randomseed (with os.time()).
> > 
> > If you don't change the seed, you get the same result upon each 
> > typesetting, and a seed is given in the .tuc file.
> > 
> > For example I have this:
> > ["randomseed"]=0x1.0741c18b8a4ep-6
> > 
> > How do I use (and is it possible to) this value to have the same result of 
> > math.random() upon typesetting another file (with a different name) ?
> > 
> > I could provide a same fixed seed in both files, but for some reasons I 
> > would like to re-use some previous results of math.random() for which no 
> > seed was initially given in another .tex file.
> You have to go low level ...
> 
> % \ctxlua{utilities.randomizer.setseed(0x1.0741c18b8a4ep-6)}
> % \ctxlua{utilities.randomizer.setseed(0x1.6822232009d5p-5)}
> 
> \setrandomseed{123}
> 
> \starttext
> test \randomnumber{1}{100}
> test \randomnumber{1}{100}
> test \randomnumber{1}{100}
> \stoptext
> 
> btw, the 0x representation is lua's low level binary representation of a
> double.
> 
> Hans
> 
> -
>   Hans Hagen | PRAGMA ADE
>   Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Hans Hagen via ntg-context

On 8/23/2021 5:24 PM, Hans van der Meer via ntg-context wrote:
I guess the underlying library calls are from Lua5.4? Then it is perhaps 
useful to know that between 5.3 and 5.4 there is mentioned a new 
implementation for math.random. Perhaps it changes the sequence of 
random values generated? Someone who knows?
I suppose that usage is within a certain timeframe and therefore version 
of lua(meta)tex so then setting the seed should work ok.


Hans



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Henri Menke via ntg-context
On Mon, 2021-08-23 at 17:24 +0200, Hans van der Meer via ntg-context
wrote:
> I guess the underlying library calls are from Lua5.4? Then it is
> perhaps useful to know that between 5.3 and 5.4 there is mentioned a
> new implementation for math.random. Perhaps it changes the sequence of
> random values generated? Someone who knows?

https://tex.stackexchange.com/questions/468466/tikz-graphdrawing-differences-between-luatex-versions

Cheers, Henri

> 
> dr. Hans van der Meer
> 
> 
> > On 23 Aug 2021, at 17:13, Hans Hagen via ntg-context <
> > ntg-context@ntg.nl> wrote:
> > 
> > On 8/23/2021 4:46 PM, Thierry Horsin via ntg-context wrote:
> > > Hi everybody.
> > > I wonder how does math.random() work in context. I found that this
> > > subject was discussed more than ten years ago by Otared and Taco
> > > and Thomas. It is clear to me how to obtain new results upon
> > > typesetting the same file by changing the value of math.randomseed
> > > (with os.time()).
> > > If you don't change the seed, you get the same result upon each
> > > typesetting, and a seed is given in the .tuc file.
> > > For example I have this:
> > > ["randomseed"]=0x1.0741c18b8a4ep-6
> > > How do I use (and is it possible to) this value to have the same
> > > result of math.random() upon typesetting another file (with a
> > > different name) ?
> > > I could provide a same fixed seed in both files, but for some
> > > reasons I would like to re-use some previous results of
> > > math.random() for which no seed was initially given in another .tex
> > > file.
> > You have to go low level ...
> > 
> > % \ctxlua{utilities.randomizer.setseed(0x1.0741c18b8a4ep-6)}
> > % \ctxlua{utilities.randomizer.setseed(0x1.6822232009d5p-5)}
> > 
> > \setrandomseed{123}
> > 
> > \starttext
> >    test \randomnumber{1}{100}
> >    test \randomnumber{1}{100}
> >    test \randomnumber{1}{100}
> > \stoptext
> > 
> > btw, the 0x representation is lua's low level binary representation
> > of a double.
> > 
> > Hans
> > 
> > -
> >  Hans Hagen | PRAGMA ADE
> >  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> >   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> > -
> > _
> > __
> > If your question is of interest to others as well, please add an
> > entry to the Wiki!
> > 
> > maillist : ntg-context@ntg.nl / 
> > http://www.ntg.nl/mailman/listinfo/ntg-context
> > webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> > archive  : https://bitbucket.org/phg/context-mirror/commits/
> > wiki : http://contextgarden.net
> > _
> > __
> 
> ___
> 
> If your question is of interest to others as well, please add an entry
> to the Wiki!
> 
> maillist : ntg-context@ntg.nl / 
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___
> 


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Hans van der Meer via ntg-context
I guess the underlying library calls are from Lua5.4? Then it is perhaps useful 
to know that between 5.3 and 5.4 there is mentioned a new implementation for 
math.random. Perhaps it changes the sequence of random values generated? 
Someone who knows?

dr. Hans van der Meer


> On 23 Aug 2021, at 17:13, Hans Hagen via ntg-context  
> wrote:
> 
> On 8/23/2021 4:46 PM, Thierry Horsin via ntg-context wrote:
>> Hi everybody.
>> I wonder how does math.random() work in context. I found that this subject 
>> was discussed more than ten years ago by Otared and Taco and Thomas. It is 
>> clear to me how to obtain new results upon typesetting the same file by 
>> changing the value of math.randomseed (with os.time()).
>> If you don't change the seed, you get the same result upon each typesetting, 
>> and a seed is given in the .tuc file.
>> For example I have this:
>> ["randomseed"]=0x1.0741c18b8a4ep-6
>> How do I use (and is it possible to) this value to have the same result of 
>> math.random() upon typesetting another file (with a different name) ?
>> I could provide a same fixed seed in both files, but for some reasons I 
>> would like to re-use some previous results of math.random() for which no 
>> seed was initially given in another .tex file.
> You have to go low level ...
> 
> % \ctxlua{utilities.randomizer.setseed(0x1.0741c18b8a4ep-6)}
> % \ctxlua{utilities.randomizer.setseed(0x1.6822232009d5p-5)}
> 
> \setrandomseed{123}
> 
> \starttext
>test \randomnumber{1}{100}
>test \randomnumber{1}{100}
>test \randomnumber{1}{100}
> \stoptext
> 
> btw, the 0x representation is lua's low level binary representation of a 
> double.
> 
> Hans
> 
> -
>  Hans Hagen | PRAGMA ADE
>  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -
> ___
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Henri Menke via ntg-context
On Mon, 2021-08-23 at 16:46 +0200, Thierry Horsin via ntg-context
wrote:
> Hi everybody.
> 
> I wonder how does math.random() work in context. I found that this
> subject was discussed more than ten years ago by Otared and Taco and
> Thomas. It is clear to me how to obtain new results upon typesetting
> the same file by changing the value of math.randomseed (with
> os.time()).
> 
> If you don't change the seed, you get the same result upon each
> typesetting, and a seed is given in the .tuc file.
> 
> For example I have this:
> ["randomseed"]=0x1.0741c18b8a4ep-6
> 
> How do I use (and is it possible to) this value to have the same
> result of math.random() upon typesetting another file (with a
> different name) ?
> 
> I could provide a same fixed seed in both files, but for some reasons
> I would like to re-use some previous results of math.random() for
> which no seed was initially given in another .tex file.

You can immediately forget about that, because in the past Lua has
switched the random number generator (RNG) between releases and also
uses a different RNG depending on the operating system. In general it
is a really bad idea to depend on the exact sequence of random numbers.

As an alternative you can just pregenerate a list of random numbers and
copy that to other documents.

Cheers, Henri

> 
> Thank you
> Thierry
> _
> __
> If your question is of interest to others as well, please add an
> entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / 
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> _
> __


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Hans Hagen via ntg-context

On 8/23/2021 4:46 PM, Thierry Horsin via ntg-context wrote:

Hi everybody.

I wonder how does math.random() work in context. I found that this subject was 
discussed more than ten years ago by Otared and Taco and Thomas. It is clear to 
me how to obtain new results upon typesetting the same file by changing the 
value of math.randomseed (with os.time()).

If you don't change the seed, you get the same result upon each typesetting, 
and a seed is given in the .tuc file.

For example I have this:
["randomseed"]=0x1.0741c18b8a4ep-6

How do I use (and is it possible to) this value to have the same result of 
math.random() upon typesetting another file (with a different name) ?

I could provide a same fixed seed in both files, but for some reasons I would 
like to re-use some previous results of math.random() for which no seed was 
initially given in another .tex file.

You have to go low level ...

% \ctxlua{utilities.randomizer.setseed(0x1.0741c18b8a4ep-6)}
% \ctxlua{utilities.randomizer.setseed(0x1.6822232009d5p-5)}

\setrandomseed{123}

\starttext
test \randomnumber{1}{100}
test \randomnumber{1}{100}
test \randomnumber{1}{100}
\stoptext

btw, the 0x representation is lua's low level binary representation of a 
double.


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2021-08-23 Thread Thierry Horsin via ntg-context
Hi everybody.

I wonder how does math.random() work in context. I found that this subject was 
discussed more than ten years ago by Otared and Taco and Thomas. It is clear to 
me how to obtain new results upon typesetting the same file by changing the 
value of math.randomseed (with os.time()).

If you don't change the seed, you get the same result upon each typesetting, 
and a seed is given in the .tuc file.

For example I have this:
["randomseed"]=0x1.0741c18b8a4ep-6

How do I use (and is it possible to) this value to have the same result of 
math.random() upon typesetting another file (with a different name) ?

I could provide a same fixed seed in both files, but for some reasons I would 
like to re-use some previous results of math.random() for which no seed was 
initially given in another .tex file.

Thank you
Thierry
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2009-10-25 Thread Taco Hoekwater

Otared KAVIAN wrote:


Indeed I guess that this is due to the random seed used by LuaTeX: is it
possible to force a new random seed upon each typesetting?


The randomseed is set by context, and saved between consecutive runs of
the same file. Normally, this is what you would want: just imagine what
happens if each of the luatex runs in a 'context' call used a different
value always.

However (this is mostly for Hans), there is a bug in that process: all
randomseeds in mkiv appear to be between 0 and 1. Since 
math.randomseed() expects an integer, this gives almost no

randomness at all to the seed values.

If you want near-random randomness, you can set the seed yourself
based on the return value of os.time():

  \ctxlua{math.randomseed(os.time())}

Best wishes,
Taco



___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2009-10-25 Thread Thomas A. Schmitz


On Oct 25, 2009, at 9:26 AM, Taco Hoekwater wrote:


Otared KAVIAN wrote:
Indeed I guess that this is due to the random seed used by LuaTeX:  
is it

possible to force a new random seed upon each typesetting?


The randomseed is set by context, and saved between consecutive runs  
of
the same file. Normally, this is what you would want: just imagine  
what
happens if each of the luatex runs in a 'context' call used a  
different

value always.

However (this is mostly for Hans), there is a bug in that process: all
randomseeds in mkiv appear to be between 0 and 1. Since  
math.randomseed() expects an integer, this gives almost no

randomness at all to the seed values.

If you want near-random randomness, you can set the seed yourself
based on the return value of os.time():

 \ctxlua{math.randomseed(os.time())}


Ah, that explains why I could never get random numbers in mkiv when I  
tried a year ago. Another suggestion: there's also a \getrandomnumber  
command available in ConTeXt, which seems to work well.


Thomas
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Curiosity about math.random in LuaTeX

2009-10-25 Thread Otared Kavian
Thomas and Taco: thanks to both of you for your insight. I overlooked  
the function math.randomseed() in Lua, and my question was mainly out  
of curioisty: in practive one doesn't need to reset the random seed,  
as Taco points out.


However I couldn't find the right usage of the command «  
\getrandomnumber »…


Best regards: OK

On 25 oct. 2009, at 10:50, Thomas A. Schmitz wrote:



On Oct 25, 2009, at 9:26 AM, Taco Hoekwater wrote:


Otared KAVIAN wrote:
Indeed I guess that this is due to the random seed used by LuaTeX:  
is it

possible to force a new random seed upon each typesetting?


The randomseed is set by context, and saved between consecutive  
runs of
the same file. Normally, this is what you would want: just imagine  
what
happens if each of the luatex runs in a 'context' call used a  
different

value always.

However (this is mostly for Hans), there is a bug in that process:  
all
randomseeds in mkiv appear to be between 0 and 1. Since  
math.randomseed() expects an integer, this gives almost no

randomness at all to the seed values.

If you want near-random randomness, you can set the seed yourself
based on the return value of os.time():

\ctxlua{math.randomseed(os.time())}


Ah, that explains why I could never get random numbers in mkiv when  
I tried a year ago. Another suggestion: there's also a  
\getrandomnumber command available in ConTeXt, which seems to work  
well.


Thomas
___
If your question is of interest to others as well, please add an  
entry to the Wiki!


maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___