Re: [NTG-context] randomize direction of arrow in metafun

2021-05-15 Thread Thomas A. Schmitz

On 5/15/21 2:42 PM, Mikael Sundqvist wrote:

Hi,

you could do something like this:

\startMPpage
for i = 0 upto 10:
  drawarrow if uniformdeviate(1)<0.5: reverse fi ((0,0)--(2cm,0)) yshifted i*cm;
endfor;
\stopMPpage

/Mikael


Hi Mikael,

wonderful, thanks for the quick answer! Yes that works as intended!

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] randomize direction of arrow in metafun

2021-05-15 Thread Mikael Sundqvist
Hi,

you could do something like this:

\startMPpage
for i = 0 upto 10:
 drawarrow if uniformdeviate(1)<0.5: reverse fi ((0,0)--(2cm,0)) yshifted i*cm;
endfor;
\stopMPpage

/Mikael

On Sat, May 15, 2021 at 2:30 PM Thomas A. Schmitz
 wrote:
>
> Hi all,
>
> for a slide template, I want to draw colored arrows in a randomized
> color (from a list of colors). This works (and the code is far too
> clever for me, I must have copied it somewhere):
>
> save mycolor ; color mycolor[] ;
> mycolor[1] := (0.2, 0.3, 0.4) ;
> mycolor[2] := (0.6, 0.6, 0.4) ;
> mycolor[3] := (0.5, 0.8, 0.5) ;
>
> so I can write
>
> drawarrow p withcolor mycolor[round(uniformdeviate(9))] ;
>
> But I also want the direction of the arrow to be random. My first idea
> was to define a variable that would expand either to "reverse" or the
> empty string right after drawarrow, but that's where I'm stuck. Anyone
> has an idea how to achieve this? (It's probably somewhere in the source,
> but I can't find it.) And is the method of defining the random color OK,
> or could this also be improved.
>
> Thanks, and all best
>
> 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://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
___


[NTG-context] randomize direction of arrow in metafun

2021-05-15 Thread Thomas A. Schmitz

Hi all,

for a slide template, I want to draw colored arrows in a randomized 
color (from a list of colors). This works (and the code is far too 
clever for me, I must have copied it somewhere):


save mycolor ; color mycolor[] ;
mycolor[1] := (0.2, 0.3, 0.4) ;
mycolor[2] := (0.6, 0.6, 0.4) ;
mycolor[3] := (0.5, 0.8, 0.5) ;

so I can write

drawarrow p withcolor mycolor[round(uniformdeviate(9))] ;

But I also want the direction of the arrow to be random. My first idea 
was to define a variable that would expand either to "reverse" or the 
empty string right after drawarrow, but that's where I'm stuck. Anyone 
has an idea how to achieve this? (It's probably somewhere in the source, 
but I can't find it.) And is the method of defining the random color OK, 
or could this also be improved.


Thanks, and all best

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Randomize order of blocks

2021-01-06 Thread Jairo A. del Rio
Nice. I had something a little bit different in mind, but your examples
gave me some ideas, especially the shuffling stuff. If I have something new
to add, I will share my results with the list. Thank you a lot.

Best regards,

Jairo

El mié, 6 de ene. de 2021 a la(s) 03:56, Otared Kavian (ota...@gmail.com)
escribió:

> Following up my previous message, here is an example:
>
> %% begin shuffled list of exercises
> \setuprandomize[2021]
>
> \startluacode
> function shuffle(tableau)
> local maxsize, t, tt
> maxsize = #tableau
> tt = {}
> t = {}
> for i = 1, maxsize do
> t[i] = {}
> t[i]["columnOne"] = tableau[i]
> t[i]["columnTwo"] = math.random(1,100*maxsize)
> end
> table.sort(t, function(a,b) return a.columnTwo <
> b.columnTwo end)
> for i = 1, maxsize do
> tt[i] = t[i]["columnOne"]
> end
> return tt
> end
> \stopluacode
>
> % We define three arrays
> % with the names, the functions and their derivatives
> % One could also add a ListOfVariables...
>
> \startluacode
>
> ListOfNames = {
> "f",
> "g",
> "h",
> "u",
> "v",
> "F",
> "G",
> "H",
> }
>
> ListOfFunctions = {
> "\\cos(x^2)",
> "x\\sin(x)",
> "\\tan(x)",
> "x^3 - 3x^2 + 1",
> "\\frac{1}{1 + x^2}",
> "\\sin(\\log(x))",
> }
>
> ListOfDerivatives = {
> "-2x\\sin(x^2)",
> "x\\cos(x) + \\sin(x)",
> "1 + \\tan(x)^2",
> "3x^2 - 6x",
> "\\frac{-2x}{(1 + x^2)^2}",
> "\\frac{\\cos(\\log(x))}{x}",
> }
>
> \stopluacode
>
> \starttext
>
> % We define a buffer and a shuffled list of integers
>
> \startbuffer[test-derivatives]
> \startluacode
> ShuffledList = shuffle({1,2,3,4,5,6})
> \stopluacode
>
> Let $\cldcontext{ListOfNames[ShuffledList[\recurselevel]]}(x) :=
> \cldcontext{ListOfFunctions[ShuffledList[\recurselevel]]}$. Prove that
> \startformula
> \cldcontext{ListOfNames[ShuffledList[\recurselevel]]}'(x) =
> \cldcontext{ListOfDerivatives[ShuffledList[\recurselevel]]}
> \stopformula
> \stopbuffer
>
> \dorecurse{6}{\blank[medium]{\bf Exercise #1.}
> \getbuffer[test-derivatives]
> }
>
> \stoptext
>
> %% end shuffled list of exercises
>
>
> > On 6 Jan 2021, at 09:41, Otared Kavian  wrote:
> >
> > Hi Jairo,
> >
> > One can indeed make quizzes and exams with randomized order of problems,
> randomized values and even randomized names of functions and variables.
> > I have some examples which I have been using for several years (they are
> useful especially in these days of giving exams online…): I can send them
> to you as they are, or if you tell me what kind of problems you want, then
> I can adapt my examples before sending them to you.
> >
> > Best regards: Otared
> >
> >> On 5 Jan 2021, at 17:18, Jairo A. del Rio 
> wrote:
> >>
> >> Hi, list.
> >>
> >> Some time ago I realized ConTeXt has "blocks" which allow one to make
> quizzes, exams and related with ease. However, I want to know if there's an
> option to randomize their order when printed. Thank you in advance.
> >>
> >> Jairo
> >>
> ___
> >> 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/

Re: [NTG-context] Randomize order of blocks

2021-01-06 Thread Otared Kavian
Following up my previous message, here is an example:

%% begin shuffled list of exercises
\setuprandomize[2021]

\startluacode
function shuffle(tableau)
local maxsize, t, tt
maxsize = #tableau
tt = {}
t = {}
for i = 1, maxsize do
t[i] = {}
t[i]["columnOne"] = tableau[i]
t[i]["columnTwo"] = math.random(1,100*maxsize)
end
table.sort(t, function(a,b) return a.columnTwo < b.columnTwo 
end)
for i = 1, maxsize do
tt[i] = t[i]["columnOne"]
end
return tt
end
\stopluacode

% We define three arrays
% with the names, the functions and their derivatives
% One could also add a ListOfVariables...

\startluacode

ListOfNames = {
"f",
"g",
"h",
"u",
"v",
"F",
"G",
"H",
}

ListOfFunctions = {
"\\cos(x^2)",
"x\\sin(x)",
"\\tan(x)",
"x^3 - 3x^2 + 1",
"\\frac{1}{1 + x^2}",
"\\sin(\\log(x))",
}

ListOfDerivatives = {
"-2x\\sin(x^2)",
"x\\cos(x) + \\sin(x)",
"1 + \\tan(x)^2",
"3x^2 - 6x",
"\\frac{-2x}{(1 + x^2)^2}",
"\\frac{\\cos(\\log(x))}{x}",
}

\stopluacode

\starttext

% We define a buffer and a shuffled list of integers

\startbuffer[test-derivatives]
\startluacode
ShuffledList = shuffle({1,2,3,4,5,6})
\stopluacode

Let $\cldcontext{ListOfNames[ShuffledList[\recurselevel]]}(x) := 
\cldcontext{ListOfFunctions[ShuffledList[\recurselevel]]}$. Prove that
\startformula
\cldcontext{ListOfNames[ShuffledList[\recurselevel]]}'(x) = 
\cldcontext{ListOfDerivatives[ShuffledList[\recurselevel]]}
\stopformula
\stopbuffer

\dorecurse{6}{\blank[medium]{\bf Exercise #1.}
\getbuffer[test-derivatives]
}

\stoptext

%% end shuffled list of exercises


> On 6 Jan 2021, at 09:41, Otared Kavian  wrote:
> 
> Hi Jairo,
> 
> One can indeed make quizzes and exams with randomized order of problems, 
> randomized values and even randomized names of functions and variables.
> I have some examples which I have been using for several years (they are 
> useful especially in these days of giving exams online…): I can send them to 
> you as they are, or if you tell me what kind of problems you want, then I can 
> adapt my examples before sending them to you.
> 
> Best regards: Otared 
> 
>> On 5 Jan 2021, at 17:18, Jairo A. del Rio  wrote:
>> 
>> Hi, list.
>> 
>> Some time ago I realized ConTeXt has "blocks" which allow one to make 
>> quizzes, exams and related with ease. However, I want to know if there's an 
>> option to randomize their order when printed. Thank you in advance.
>> 
>> Jairo
>> ___
>> 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] Randomize order of blocks

2021-01-06 Thread Otared Kavian
Hi Jairo,

One can indeed make quizzes and exams with randomized order of problems, 
randomized values and even randomized names of functions and variables.
I have some examples which I have been using for several years (they are useful 
especially in these days of giving exams online…): I can send them to you as 
they are, or if you tell me what kind of problems you want, then I can adapt my 
examples before sending them to you.

Best regards: Otared 

> On 5 Jan 2021, at 17:18, Jairo A. del Rio  wrote:
> 
> Hi, list.
> 
> Some time ago I realized ConTeXt has "blocks" which allow one to make 
> quizzes, exams and related with ease. However, I want to know if there's an 
> option to randomize their order when printed. Thank you in advance.
> 
> Jairo
> ___
> 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
___


[NTG-context] Randomize order of blocks

2021-01-05 Thread Jairo A. del Rio
Hi, list.

Some time ago I realized ConTeXt has "blocks" which allow one to make
quizzes, exams and related with ease. However, I want to know if there's an
option to randomize their order when printed. Thank you in advance.

Jairo
___
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] Randomize control points in metapost/metafun?

2016-08-01 Thread Hans Hagen

On 8/1/2016 12:47 PM, Mikael P. Sundqvist wrote:


Wow! That was fast! I just updated and it indeed works as expected.

I hate to ask another thing when I just got this fast and nice help,
but is there also a way to change the control points in such a way
that no _new_ sharp corners occur?


that's a challenge for alan (who likes mp challenges) as it involves math

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] Randomize control points in metapost/metafun?

2016-08-01 Thread Mikael P. Sundqvist
On Mon, Aug 1, 2016 at 10:12 AM, Hans Hagen  wrote:
> On 8/1/2016 8:03 AM, Mikael P. Sundqvist wrote:
>>
>> Hi!
>>
>> I look for a way to randomize control points of a path, leaving the
>> coordinates themselves untouched.
>>
>> The reason is the following: I want to draw (for example) a circle
>> with a triangle inside, and I want them to look slightly randomized.
>> If I do (see attached pdf for a typical result of this)
>>
>> \startMPpage
>> draw fullcircle scaled 2cm randomized 0.1cm;
>> draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle) randomized 0.1cm;
>> \stopMPpage
>>
>> then the corners of the triangle does not stay on the circle (and I
>> want them to). [I dont want the triangle to consist of perfectly
>> straight lines, so I cannot (directly) draw the triangle using
>> different points along the randomized circle] I imagine that one could
>> achieve what I want if one could randomize the control points only.
>
>
> i'll add
>
> primarydef p randomizedcontrols s = (
> if path p :
> for i=0 upto length(p)-1 :
>  (point   iof p) .. controls
> ((postcontrol iof p) randomshifted s) and
> ((precontrol (i+1) of p) randomshifted s) ..
> endfor
> if cycle p :
> cycle
> else :
> (point length(p) of p)
> fi
> else :
> p randomized s
> fi
> ) enddef ;
>
>> Also, is it possible to randomize a picture (consisting of several
>> paths/points) somehow, without randomizing each part of it manually?
>
>
> so:
>
> vardef mfun_randomized_path(expr p,s) =
> for i=0 upto length(p)-1 :
>  (point   iof p) .. controls
> ((postcontrol iof p) randomshifted s) and
> ((precontrol (i+1) of p) randomshifted s) ..
> endfor
> if cycle p :
> cycle
> else :
> (point length(p) of p)
> fi
> enddef;
>
> vardef mfun_randomized_picture(expr p,s) =
> save currentpicture ;
> picture currentpicture ;
> currentpicture := nullpicture ;
> for i within p :
> addto currentpicture
> if stroked i :
> doublepath pathpart i randomizedcontrols s
> dashed dashpart i
> withpen penpart i
> withcolor colorpart i
> withprescript prescriptpart i
> withpostscript postscriptpart i
> elseif filled i :
> contour pathpart i randomizedcontrols s
> withpen penpart i
> withcolor colorpart i
> withprescript prescriptpart i
> withpostscript postscriptpart i
> else :
> also i
> fi
> ;
> endfor ;
> currentpicture
> enddef ;
>
> primarydef p randomizedcontrols s = (
> if path p :
> mfun_randomized_path(p,s)
> elseif picture p :
> mfun_randomized_picture(p,s)
> else :
> p randomized s
> fi
> ) enddef ;
>
> with
>
> draw fullcircle scaled 2cm randomizedcontrols 0.1cm;
> draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle) randomizedcontrols 0.1cm;
>
> draw image (
> draw fullcircle scaled 2cm ;
> draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle);
> ) randomizedcontrols 0.1cm ;
>
>
>
> -
>   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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___

Wow! That was fast! I just updated and it indeed works as expected.

I hate to ask another thing when I just got this fast and nice help,
but is there also a way to change the control points in such a way
that no _new_ sharp corners occur?

/Mikael
___
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] Randomize control points in metapost/metafun?

2016-08-01 Thread Hans Hagen

On 8/1/2016 8:03 AM, Mikael P. Sundqvist wrote:

Hi!

I look for a way to randomize control points of a path, leaving the
coordinates themselves untouched.

The reason is the following: I want to draw (for example) a circle
with a triangle inside, and I want them to look slightly randomized.
If I do (see attached pdf for a typical result of this)

\startMPpage
draw fullcircle scaled 2cm randomized 0.1cm;
draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle) randomized 0.1cm;
\stopMPpage

then the corners of the triangle does not stay on the circle (and I
want them to). [I dont want the triangle to consist of perfectly
straight lines, so I cannot (directly) draw the triangle using
different points along the randomized circle] I imagine that one could
achieve what I want if one could randomize the control points only.


i'll add

primarydef p randomizedcontrols s = (
if path p :
for i=0 upto length(p)-1 :
 (point   iof p) .. controls
((postcontrol iof p) randomshifted s) and
((precontrol (i+1) of p) randomshifted s) ..
endfor
if cycle p :
cycle
else :
(point length(p) of p)
fi
else :
p randomized s
fi
) enddef ;


Also, is it possible to randomize a picture (consisting of several
paths/points) somehow, without randomizing each part of it manually?


so:

vardef mfun_randomized_path(expr p,s) =
for i=0 upto length(p)-1 :
 (point   iof p) .. controls
((postcontrol iof p) randomshifted s) and
((precontrol (i+1) of p) randomshifted s) ..
endfor
if cycle p :
cycle
else :
(point length(p) of p)
fi
enddef;

vardef mfun_randomized_picture(expr p,s) =
save currentpicture ;
picture currentpicture ;
currentpicture := nullpicture ;
for i within p :
addto currentpicture
if stroked i :
doublepath pathpart i randomizedcontrols s
dashed dashpart i
withpen penpart i
withcolor colorpart i
withprescript prescriptpart i
withpostscript postscriptpart i
elseif filled i :
contour pathpart i randomizedcontrols s
withpen penpart i
withcolor colorpart i
withprescript prescriptpart i
withpostscript postscriptpart i
else :
also i
fi
;
endfor ;
currentpicture
enddef ;

primarydef p randomizedcontrols s = (
if path p :
mfun_randomized_path(p,s)
elseif picture p :
mfun_randomized_picture(p,s)
else :
p randomized s
fi
) enddef ;

with

draw fullcircle scaled 2cm randomizedcontrols 0.1cm;
draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle) randomizedcontrols 0.1cm;

draw image (
draw fullcircle scaled 2cm ;
draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle);
) randomizedcontrols 0.1cm ;



-
  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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

[NTG-context] Randomize control points in metapost/metafun?

2016-08-01 Thread Mikael P. Sundqvist
Hi!

I look for a way to randomize control points of a path, leaving the
coordinates themselves untouched.

The reason is the following: I want to draw (for example) a circle
with a triangle inside, and I want them to look slightly randomized.
If I do (see attached pdf for a typical result of this)

\startMPpage
draw fullcircle scaled 2cm randomized 0.1cm;
draw ((1cm,0)--(0,1cm)--(-1cm,0)--cycle) randomized 0.1cm;
\stopMPpage

then the corners of the triangle does not stay on the circle (and I
want them to). [I dont want the triangle to consist of perfectly
straight lines, so I cannot (directly) draw the triangle using
different points along the randomized circle] I imagine that one could
achieve what I want if one could randomize the control points only.

Also, is it possible to randomize a picture (consisting of several
paths/points) somehow, without randomizing each part of it manually?

/Mikael


ctx-listexample.pdf
Description: Adobe PDF document
___
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] randomize

2010-04-08 Thread Wolfgang Werners-Lucchini
  I know this and I have triggerd this by hand. So there is a lot of
  time between. I have purged files between every run and I got the
  same result if I wait 1 second, 1 minute or 1 day.
 
   Well, then it probably qualifies as a bug, and, since the .tuc
 file
 has apparently been dismissed as a cause,  you'd have to provide
 more
 precise information if you're interested in having it corrected (or
 do the debugging yourself, of course).
 
   Arthur

I have found a discussion on this thema. See

http://lua-users.org/lists/lua-l/2007-03/msg00564.html

So I have changed the example to

-
\starttext
\startluacode
math.randomseed(os.time())
_=math.random()
\stopluacode

Encode your Name and Surname as a
\startluacode
local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
context('%s string', a[math.random(1,3)])
\stopluacode
\stoptext
-

and this is working ok!

Wolfgang
___
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] randomize

2010-04-08 Thread Arthur Reutenauer
 http://lua-users.org/lists/lua-l/2007-03/msg00564.html

  Interesting, thanks for the research.  So now we know you use a Mac :-)

Arthur
___
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] randomize

2010-04-08 Thread Wolfgang Schuster

Am 08.04.10 09:41, schrieb Arthur Reutenauer:

http://lua-users.org/lists/lua-l/2007-03/msg00564.html
 

Interesting, thanks for the research.  So now we know you use a Mac :-)
   

Sure? I think he use windows, take a look at the mail header:

Pegasus Mail for Windows (4.41, DE v4.41 R1)

Wolfgang

___
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] randomize

2010-04-08 Thread Arthur Reutenauer
 Sure? I think he use windows, take a look at the mail header:

 Pegasus Mail for Windows (4.41, DE v4.41 R1)

  Right, I was misled by the thread on the Lua list he pointed to, that
focused on the rand() implementation on Mac OS and other BSD descendants
(I had overseen that it mentioned the same problem also happened on
Windows).  But let's drop the discussion there, lest Anonymous ConTeXt
User starts worrying we're going to track him down, too :-) (I have
contacts at Google on different continents!)

Arthur
___
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] randomize

2010-04-07 Thread Wolfgang Schuster

Am 07.04.10 01:10, schrieb Wolfgang Werners-Lucchini:

Delete the tuc file with 'context --purgeall'.
 

This does not work! I get allways the same.
   

Delete

\startluacode
math.randomseed(os.time())
\stopluacode

in your file.

Wolfgang

___
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] randomize

2010-04-07 Thread Hans Hagen

On 7-4-2010 5:05, Aditya Mahajan wrote:

On Tue, 6 Apr 2010, Wolfgang Werners-Lucchini wrote:


Hallo,

I get allways (10 times at least) the same result:
-
\starttext
\startluacode
math.randomseed(os.time())
\stopluacode

Encode your Name and Surname as a
\startluacode
local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
context('%s string', a[math.random(1,3)])
\stopluacode
\stoptext
-
How can I randomize this?


Hmm... which version are you using? I do get a ranom output each time.
Tested with 2009.12.31 and 2010.03.20.

Since the math seed is set after \starttext, it should overwrite the
value after reading the tuc file.

Actually, I consider saving the random number in tuc file to be a
misfeature. A random sequence generator should generate a random
sequence. If I want the same behavior all the time, I can use
\setupsystem[random=12345] (which should also set math.randomseed).


the reason is that otherwise (esp if the randomization produced 
different input, graphic sizes, etc) you can get oscilation and endless 
runs due to never quite right multipass data which is pretty hard to debug


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
-
___
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] randomize

2010-04-07 Thread luigi scarso
On Wed, Apr 7, 2010 at 5:05 AM, Aditya Mahajan adit...@umich.edu wrote:
 On Tue, 6 Apr 2010, Wolfgang Werners-Lucchini wrote:

 Hallo,

 I get allways (10 times at least) the same result:
 -
 \starttext
 \startluacode
 math.randomseed(os.time())
 \stopluacode

 Encode your Name and Surname as a
 \startluacode
 local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
 context('%s string', a[math.random(1,3)])
 \stopluacode
 \stoptext
 -
 How can I randomize this?

 Hmm... which version are you using?  I do get a ranom output each time.
 Tested with 2009.12.31 and  2010.03.20.

 Since the math seed is set after \starttext, it should overwrite the value
 after reading the tuc file.

Same here:

# for j in `seq 1 100`; do context test.tex  /dev/null; pdftotext
test.pdf  -|grep Encode; done  out

# nl out |tail -1
   100  Encode your Name and Surname as a null-terminated string

# grep 'Encode your Name and Surname as a Pascal string' out |nl|tail -1
33  Encode your Name and Surname as a Pascal string

# grep 'Encode your Name and Surname as a dollar-terminated string'
out |nl|tail -1
35  Encode your Name and Surname as a dollar-terminated string

# grep 'Encode your Name and Surname as a null-terminated string' out
|nl|tail -1
32  Encode your Name and Surname as a null-terminated string

which is pretty good for only 100 samples

-- 
luigi
___
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] randomize

2010-04-07 Thread Wolfgang Werners-Lucchini
  I get allways (10 times at least) the same result:
  -
  \starttext
  \startluacode
  math.randomseed(os.time())
  \stopluacode
 
  Encode your Name and Surname as a
  \startluacode
  local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
  context('%s string', a[math.random(1,3)])
  \stopluacode
  \stoptext
  -
  How can I randomize this?
 
 Hmm... which version are you using?  I do get a ranom output each
 time.
 Tested with 2009.12.31 and  2010.03.20.

This is LuaTeX, Version beta-0.60.0-2010040521 (rev 3596) 
 \write18 enabled.
(tst-b.tex

ConTeXt  ver: 2010.03.30 18:56 MKIV  fmt: 2010.4.7  int: 
english/english
 
 Since the math seed is set after \starttext, it should overwrite the
 value after reading the tuc file.
 
 Actually, I consider saving the random number in tuc file to be a 
 misfeature. A random sequence generator should generate a random
 sequence. 
 If I want the same behavior all the time, I can use 
 \setupsystem[random=12345] (which should also set 
 math.randomseed).

I agree with this!
A feature could be to save the last used random value in the tuc, so 
that one can continue with the former used sequenz. But this should 
not be used automatically, too. May be one should than say

\setupsystem[random=last]

Wolfgang

___
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] randomize

2010-04-07 Thread Wolfgang Werners-Lucchini
  Delete the tuc file with 'context --purgeall'.
   
  This does not work! I get allways the same.
 
 Delete
 
 \startluacode
 math.randomseed(os.time())
 \stopluacode
 
 in your file.

Now it works. But WHY?

Wolfgang
___
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] randomize

2010-04-07 Thread Arthur Reutenauer
 Now it works. But WHY?

  Because that's the way random number generators works.  They're not
random at all, they generate completely predictable number sequences
from a seed: each time you use the same seed, you get the exact same
sequence.  In your case, you used os.time() as a seed, which is an
integral number of seconds elapsed since some fixed date, and the fact
you saw the same number ten times simply means your code was ran ten
times within the same second.

Arthur
___
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] randomize

2010-04-07 Thread Wolfgang Werners-Lucchini
  Now it works. But WHY?
 
   Because that's the way random number generators works.  They're
 not
 random at all, they generate completely predictable number
 sequences
 from a seed: each time you use the same seed, you get the exact
 same
 sequence.  In your case, you used os.time() as a seed, which is an
 integral number of seconds elapsed since some fixed date, and the
 fact
 you saw the same number ten times simply means your code was ran
 ten
 times within the same second.

I know this and I have triggerd this by hand. So there is a lot of 
time between. I have purged files between every run and I got the 
same result if I wait 1 second, 1 minute or 1 day.

Wolfgang
___
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] randomize

2010-04-07 Thread Arthur Reutenauer
 I know this and I have triggerd this by hand. So there is a lot of 
 time between. I have purged files between every run and I got the 
 same result if I wait 1 second, 1 minute or 1 day.

  Well, then it probably qualifies as a bug, and, since the .tuc file
has apparently been dismissed as a cause,  you'd have to provide more
precise information if you're interested in having it corrected (or do
the debugging yourself, of course).

Arthur
___
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] randomize

2010-04-06 Thread Wolfgang Werners-Lucchini
 Am 06.04.10 00:21, schrieb Wolfgang Werners-Lucchini:
  Hallo,
 
  I get allways (10 times at least) the same result:
  -
  \starttext
  \startluacode
  math.randomseed(os.time())
  \stopluacode
 
  Encode your Name and Surname as a
  \startluacode
  local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
  context('%s string', a[math.random(1,3)])
  \stopluacode
  \stoptext
  -
  How can I randomize this?
 
 ConTeXt saves the random value in the tuc file to get the same
 output in 
 each run.
 
 Delete the tuc file with 'context --purgeall'.

This does not work! I get allways the same.

And shouldn't the tuc-seed be overwriten from my os.time-seed?

Wolfgang
___
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] randomize

2010-04-06 Thread Aditya Mahajan

On Tue, 6 Apr 2010, Wolfgang Werners-Lucchini wrote:


Hallo,

I get allways (10 times at least) the same result:
-
\starttext
\startluacode
math.randomseed(os.time())
\stopluacode

Encode your Name and Surname as a
\startluacode
local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
context('%s string', a[math.random(1,3)])
\stopluacode
\stoptext
-
How can I randomize this?


Hmm... which version are you using?  I do get a ranom output each time.
Tested with 2009.12.31 and  2010.03.20.

Since the math seed is set after \starttext, it should overwrite the value 
after reading the tuc file.


Actually, I consider saving the random number in tuc file to be a 
misfeature. A random sequence generator should generate a random sequence. 
If I want the same behavior all the time, I can use 
\setupsystem[random=12345] (which should also set 
math.randomseed).


Aditya
___
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
___


[NTG-context] randomize

2010-04-05 Thread Wolfgang Werners-Lucchini
Hallo,

I get allways (10 times at least) the same result:
-
\starttext
\startluacode
math.randomseed(os.time())
\stopluacode

Encode your Name and Surname as a
\startluacode
local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
context('%s string', a[math.random(1,3)])
\stopluacode
\stoptext
-
How can I randomize this?

Wolfgang
___
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] randomize

2010-04-05 Thread Wolfgang Schuster

Am 06.04.10 00:21, schrieb Wolfgang Werners-Lucchini:

Hallo,

I get allways (10 times at least) the same result:
-
\starttext
\startluacode
math.randomseed(os.time())
\stopluacode

Encode your Name and Surname as a
\startluacode
local a = {'null-terminated', 'dollar-terminated', 'Pascal'}
context('%s string', a[math.random(1,3)])
\stopluacode
\stoptext
-
How can I randomize this?
   
ConTeXt saves the random value in the tuc file to get the same output in 
each run.


Delete the tuc file with 'context --purgeall'.

Wolfgang

___
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
___


[NTG-context] randomize a color

2006-03-06 Thread Johan Sandblom
The following produces one red square and two black ones, as opposed
to one red and two randomly perturbed but also red ones I was hoping
for. To my poor understanding this usage seems to comply with that
defined in mp-tool.mp. What am I doing wrong.

Regards, Johan

\setupcolors[state=start]
\definecolor[tilered][r=.425, g=0, b=0]
\definecolor[smudge][r=.1, g=.1, b=.1]

\defineoverlay[page][\useMPgraphic{page}]
\setupbackgrounds[page][background=page]

\startuseMPgraphic{page}
fill unitsquare scaled 2cm withcolor \MPcolor{tilered} ;
fill unitsquare
  scaled 2cm
  shifted (2cm,0cm)
  withcolor \MPcolor{tilered} randomized .1 ;
fill unitsquare
  scaled 2cm
  shifted (4cm,0cm)
  withcolor \MPcolor{tilered} randomized \MPcolor{smudge} ;
\stopuseMPgraphic

\starttext

test

\stoptext
--
Johan Sandblom  N8, MRC, Karolinska sjh
t +46851776108  17176 Stockholm
m +46735521477  Sweden
What is wanted is not the will to believe, but the
will to find out, which is the exact opposite
- Bertrand Russell
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] randomize a color

2006-03-06 Thread Taco Hoekwater


Johan Sandblom wrote:
 The following produces one red square and two black ones, as opposed
 to one red and two randomly perturbed but also red ones I was hoping
 for. To my poor understanding this usage seems to comply with that
 defined in mp-tool.mp. What am I doing wrong.

hint: your redpart gets a random value between 0 and 0.0425

Cheers, taco
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] randomize a color

2006-03-06 Thread Johan Sandblom
Well, being stupid isn't much fun, you know. One of the few
consolations is bothering knowledgable people with questions that you
are unable to figure out the (albeit obvious) answer to ...

Thank you, Johan

2006/3/6, Taco Hoekwater [EMAIL PROTECTED]:


 Johan Sandblom wrote:
  The following produces one red square and two black ones, as opposed
  to one red and two randomly perturbed but also red ones I was hoping
  for. To my poor understanding this usage seems to comply with that
  defined in mp-tool.mp. What am I doing wrong.

 hint: your redpart gets a random value between 0 and 0.0425

 Cheers, taco



--
Johan Sandblom  N8, MRC, Karolinska sjh
t +46851776108  17176 Stockholm
m +46735521477  Sweden
What is wanted is not the will to believe, but the
will to find out, which is the exact opposite
- Bertrand Russell
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context