Generate random color in way that works with both pdflatex and lualatex
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
Right now, I am generating a random color in pdftex using
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
Which works pretty well,
until I try and compile with luatex.
What is the nicest way to generate random colors (either directly or via generating 3 random numbers), that is compatible across both pdftex and luatex?
I suspect something involving pgf is the answer.
Or maybe just a condition with one branch for pdftex (that looks like the current), and one for luatex (that maybe invokes a tiny snippet of luacode).
pdftex color luatex random
add a comment |Â
up vote
7
down vote
favorite
Right now, I am generating a random color in pdftex using
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
Which works pretty well,
until I try and compile with luatex.
What is the nicest way to generate random colors (either directly or via generating 3 random numbers), that is compatible across both pdftex and luatex?
I suspect something involving pgf is the answer.
Or maybe just a condition with one branch for pdftex (that looks like the current), and one for luatex (that maybe invokes a tiny snippet of luacode).
pdftex color luatex random
2
Is theluatex85
package usable? It brings back all the deletedpdf...
macros tolualatex
â daleif
Aug 21 at 11:06
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
Right now, I am generating a random color in pdftex using
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
Which works pretty well,
until I try and compile with luatex.
What is the nicest way to generate random colors (either directly or via generating 3 random numbers), that is compatible across both pdftex and luatex?
I suspect something involving pgf is the answer.
Or maybe just a condition with one branch for pdftex (that looks like the current), and one for luatex (that maybe invokes a tiny snippet of luacode).
pdftex color luatex random
Right now, I am generating a random color in pdftex using
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
Which works pretty well,
until I try and compile with luatex.
What is the nicest way to generate random colors (either directly or via generating 3 random numbers), that is compatible across both pdftex and luatex?
I suspect something involving pgf is the answer.
Or maybe just a condition with one branch for pdftex (that looks like the current), and one for luatex (that maybe invokes a tiny snippet of luacode).
pdftex color luatex random
asked Aug 21 at 10:55
Lyndon White
1,3791129
1,3791129
2
Is theluatex85
package usable? It brings back all the deletedpdf...
macros tolualatex
â daleif
Aug 21 at 11:06
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14
add a comment |Â
2
Is theluatex85
package usable? It brings back all the deletedpdf...
macros tolualatex
â daleif
Aug 21 at 11:06
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14
2
2
Is the
luatex85
package usable? It brings back all the deleted pdf...
macros to lualatex
â daleif
Aug 21 at 11:06
Is the
luatex85
package usable? It brings back all the deleted pdf...
macros to lualatex
â daleif
Aug 21 at 11:06
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
7
down vote
accepted
The luatex85
package does
letpdfuniformdeviateuniformdeviate
You can thus do usepackageluatex85
or
documentclassarticle
usepackagexcolor
unlessifdefinedpdfuniformdeviate
letpdfuniformdeviateuniformdeviate
fi
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
extractcolorspecrandomcolortest
typeouttest
stop
This will type out something like
rgb0.84706,0.4,0.68234
with both pdflatex
or lualatex
. I guess that, when random numbers will be available also in xelatex
, a common interface will be added to the LaTeX kernel.
add a comment |Â
up vote
4
down vote
Based on Randomly assign background colour for each frame
Another approach based on pgf
:
documentclassarticle
usepackagepgf
usepackagepgffor
usepackagexcolor
usepackageifluatex
usepackageifxetex
ifluatex
letpdfrandomseedrandomseed
fi
ifxetex
pgfmathsetseedtime
else
pgfmathsetseednumberpdfrandomseed
fi
newcommandrandomcolor%
pgfmathsetmacroRrnd%
pgfmathsetmacroGrnd%
pgfmathsetmacroBrnd%
definecolorrandomcolrgbR,G,B%
begindocument
noindent%
foreach n in 1,...,1350%
randomcolorcolorrandomcolrule0.41cm0.41cm-%
enddocument
add a comment |Â
up vote
4
down vote
There is also the lcg
package (short for Linear Congruential Generator), that works with all compilers, including lualatex
. The package provides a command rand
to generate a random number and store it in the rand
counter. For use in definecolor
you should convert the counter with thevalue
.
You can set the bounds of the random generator with the package options first
and last
, and optionally change them within the document using the reinitrand
command. The default seed is based on the system clock, using the minutes as unit (so the output will change only once per minute). You can also provide a custom seed.
MWE:
documentclassarticle
usepackage[first=1,last=255]lcg
usepackagexcolor
randedefcolorathevaluerand
randedefcolorbthevaluerand
randedefcolorcthevaluerand
definecolorrandomcolorRGB
colora,
colorb,
colorc
begindocument
colorboxrandomcolorRandom color: colora,colorb,colorc
enddocument
Result:
1
Usethevaluerand
instead ofarabic
.arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).
â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to putthe
there - edited.
â Marijn
Aug 23 at 11:42
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
The luatex85
package does
letpdfuniformdeviateuniformdeviate
You can thus do usepackageluatex85
or
documentclassarticle
usepackagexcolor
unlessifdefinedpdfuniformdeviate
letpdfuniformdeviateuniformdeviate
fi
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
extractcolorspecrandomcolortest
typeouttest
stop
This will type out something like
rgb0.84706,0.4,0.68234
with both pdflatex
or lualatex
. I guess that, when random numbers will be available also in xelatex
, a common interface will be added to the LaTeX kernel.
add a comment |Â
up vote
7
down vote
accepted
The luatex85
package does
letpdfuniformdeviateuniformdeviate
You can thus do usepackageluatex85
or
documentclassarticle
usepackagexcolor
unlessifdefinedpdfuniformdeviate
letpdfuniformdeviateuniformdeviate
fi
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
extractcolorspecrandomcolortest
typeouttest
stop
This will type out something like
rgb0.84706,0.4,0.68234
with both pdflatex
or lualatex
. I guess that, when random numbers will be available also in xelatex
, a common interface will be added to the LaTeX kernel.
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
The luatex85
package does
letpdfuniformdeviateuniformdeviate
You can thus do usepackageluatex85
or
documentclassarticle
usepackagexcolor
unlessifdefinedpdfuniformdeviate
letpdfuniformdeviateuniformdeviate
fi
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
extractcolorspecrandomcolortest
typeouttest
stop
This will type out something like
rgb0.84706,0.4,0.68234
with both pdflatex
or lualatex
. I guess that, when random numbers will be available also in xelatex
, a common interface will be added to the LaTeX kernel.
The luatex85
package does
letpdfuniformdeviateuniformdeviate
You can thus do usepackageluatex85
or
documentclassarticle
usepackagexcolor
unlessifdefinedpdfuniformdeviate
letpdfuniformdeviateuniformdeviate
fi
definecolorrandomcolorRGB
pdfuniformdeviate 255,
pdfuniformdeviate 255,
pdfuniformdeviate 255
extractcolorspecrandomcolortest
typeouttest
stop
This will type out something like
rgb0.84706,0.4,0.68234
with both pdflatex
or lualatex
. I guess that, when random numbers will be available also in xelatex
, a common interface will be added to the LaTeX kernel.
answered Aug 21 at 11:32
egreg
679k8318043048
679k8318043048
add a comment |Â
add a comment |Â
up vote
4
down vote
Based on Randomly assign background colour for each frame
Another approach based on pgf
:
documentclassarticle
usepackagepgf
usepackagepgffor
usepackagexcolor
usepackageifluatex
usepackageifxetex
ifluatex
letpdfrandomseedrandomseed
fi
ifxetex
pgfmathsetseedtime
else
pgfmathsetseednumberpdfrandomseed
fi
newcommandrandomcolor%
pgfmathsetmacroRrnd%
pgfmathsetmacroGrnd%
pgfmathsetmacroBrnd%
definecolorrandomcolrgbR,G,B%
begindocument
noindent%
foreach n in 1,...,1350%
randomcolorcolorrandomcolrule0.41cm0.41cm-%
enddocument
add a comment |Â
up vote
4
down vote
Based on Randomly assign background colour for each frame
Another approach based on pgf
:
documentclassarticle
usepackagepgf
usepackagepgffor
usepackagexcolor
usepackageifluatex
usepackageifxetex
ifluatex
letpdfrandomseedrandomseed
fi
ifxetex
pgfmathsetseedtime
else
pgfmathsetseednumberpdfrandomseed
fi
newcommandrandomcolor%
pgfmathsetmacroRrnd%
pgfmathsetmacroGrnd%
pgfmathsetmacroBrnd%
definecolorrandomcolrgbR,G,B%
begindocument
noindent%
foreach n in 1,...,1350%
randomcolorcolorrandomcolrule0.41cm0.41cm-%
enddocument
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Based on Randomly assign background colour for each frame
Another approach based on pgf
:
documentclassarticle
usepackagepgf
usepackagepgffor
usepackagexcolor
usepackageifluatex
usepackageifxetex
ifluatex
letpdfrandomseedrandomseed
fi
ifxetex
pgfmathsetseedtime
else
pgfmathsetseednumberpdfrandomseed
fi
newcommandrandomcolor%
pgfmathsetmacroRrnd%
pgfmathsetmacroGrnd%
pgfmathsetmacroBrnd%
definecolorrandomcolrgbR,G,B%
begindocument
noindent%
foreach n in 1,...,1350%
randomcolorcolorrandomcolrule0.41cm0.41cm-%
enddocument
Based on Randomly assign background colour for each frame
Another approach based on pgf
:
documentclassarticle
usepackagepgf
usepackagepgffor
usepackagexcolor
usepackageifluatex
usepackageifxetex
ifluatex
letpdfrandomseedrandomseed
fi
ifxetex
pgfmathsetseedtime
else
pgfmathsetseednumberpdfrandomseed
fi
newcommandrandomcolor%
pgfmathsetmacroRrnd%
pgfmathsetmacroGrnd%
pgfmathsetmacroBrnd%
definecolorrandomcolrgbR,G,B%
begindocument
noindent%
foreach n in 1,...,1350%
randomcolorcolorrandomcolrule0.41cm0.41cm-%
enddocument
answered Aug 21 at 21:23
samcarter
74k784238
74k784238
add a comment |Â
add a comment |Â
up vote
4
down vote
There is also the lcg
package (short for Linear Congruential Generator), that works with all compilers, including lualatex
. The package provides a command rand
to generate a random number and store it in the rand
counter. For use in definecolor
you should convert the counter with thevalue
.
You can set the bounds of the random generator with the package options first
and last
, and optionally change them within the document using the reinitrand
command. The default seed is based on the system clock, using the minutes as unit (so the output will change only once per minute). You can also provide a custom seed.
MWE:
documentclassarticle
usepackage[first=1,last=255]lcg
usepackagexcolor
randedefcolorathevaluerand
randedefcolorbthevaluerand
randedefcolorcthevaluerand
definecolorrandomcolorRGB
colora,
colorb,
colorc
begindocument
colorboxrandomcolorRandom color: colora,colorb,colorc
enddocument
Result:
1
Usethevaluerand
instead ofarabic
.arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).
â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to putthe
there - edited.
â Marijn
Aug 23 at 11:42
add a comment |Â
up vote
4
down vote
There is also the lcg
package (short for Linear Congruential Generator), that works with all compilers, including lualatex
. The package provides a command rand
to generate a random number and store it in the rand
counter. For use in definecolor
you should convert the counter with thevalue
.
You can set the bounds of the random generator with the package options first
and last
, and optionally change them within the document using the reinitrand
command. The default seed is based on the system clock, using the minutes as unit (so the output will change only once per minute). You can also provide a custom seed.
MWE:
documentclassarticle
usepackage[first=1,last=255]lcg
usepackagexcolor
randedefcolorathevaluerand
randedefcolorbthevaluerand
randedefcolorcthevaluerand
definecolorrandomcolorRGB
colora,
colorb,
colorc
begindocument
colorboxrandomcolorRandom color: colora,colorb,colorc
enddocument
Result:
1
Usethevaluerand
instead ofarabic
.arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).
â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to putthe
there - edited.
â Marijn
Aug 23 at 11:42
add a comment |Â
up vote
4
down vote
up vote
4
down vote
There is also the lcg
package (short for Linear Congruential Generator), that works with all compilers, including lualatex
. The package provides a command rand
to generate a random number and store it in the rand
counter. For use in definecolor
you should convert the counter with thevalue
.
You can set the bounds of the random generator with the package options first
and last
, and optionally change them within the document using the reinitrand
command. The default seed is based on the system clock, using the minutes as unit (so the output will change only once per minute). You can also provide a custom seed.
MWE:
documentclassarticle
usepackage[first=1,last=255]lcg
usepackagexcolor
randedefcolorathevaluerand
randedefcolorbthevaluerand
randedefcolorcthevaluerand
definecolorrandomcolorRGB
colora,
colorb,
colorc
begindocument
colorboxrandomcolorRandom color: colora,colorb,colorc
enddocument
Result:
There is also the lcg
package (short for Linear Congruential Generator), that works with all compilers, including lualatex
. The package provides a command rand
to generate a random number and store it in the rand
counter. For use in definecolor
you should convert the counter with thevalue
.
You can set the bounds of the random generator with the package options first
and last
, and optionally change them within the document using the reinitrand
command. The default seed is based on the system clock, using the minutes as unit (so the output will change only once per minute). You can also provide a custom seed.
MWE:
documentclassarticle
usepackage[first=1,last=255]lcg
usepackagexcolor
randedefcolorathevaluerand
randedefcolorbthevaluerand
randedefcolorcthevaluerand
definecolorrandomcolorRGB
colora,
colorb,
colorc
begindocument
colorboxrandomcolorRandom color: colora,colorb,colorc
enddocument
Result:
edited Aug 23 at 11:41
answered Aug 21 at 16:13
Marijn
6,576531
6,576531
1
Usethevaluerand
instead ofarabic
.arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).
â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to putthe
there - edited.
â Marijn
Aug 23 at 11:42
add a comment |Â
1
Usethevaluerand
instead ofarabic
.arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).
â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to putthe
there - edited.
â Marijn
Aug 23 at 11:42
1
1
Use
thevaluerand
instead of arabic
. arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).â Ulrike Fischer
Aug 21 at 19:08
Use
thevaluerand
instead of arabic
. arabic
is a formatting command and there is no garanty that it gives a number (e.g. hebrew and arabic packages often redefine it).â Ulrike Fischer
Aug 21 at 19:08
@UlrikeFischer thanks for the improvement, it didn't occur to me to put
the
there - edited.â Marijn
Aug 23 at 11:42
@UlrikeFischer thanks for the improvement, it didn't occur to me to put
the
there - edited.â Marijn
Aug 23 at 11:42
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446944%2fgenerate-random-color-in-way-that-works-with-both-pdflatex-and-lualatex%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Is the
luatex85
package usable? It brings back all the deletedpdf...
macros tolualatex
â daleif
Aug 21 at 11:06
@daleif yes. Expand that into an answer, with a link to the docs maybe and that would be great. Assuming luatex85 is a no-op or something in pdftex
â Lyndon White
Aug 21 at 11:14