[texhax] scrambled text

Daniel Greenhoe dgreenhoe at gmail.com
Sun Aug 26 22:37:03 CEST 2012


On Sun, Aug 26, 2012 at 8:55 PM, Paul Isambert <zappathustra at free.fr> wrote:
> Indeed you can "\input random.tex" at the beginning of your document and
> replace \extractletters in my original code with this new definition:

I tried your new code and it works great---Thanks!!!

For a long time I have been using the lcg package for random number
generation. I modified your code to use lcg instead of random.tex.
However I don't know much about TeX programming. Would some one want
to take a look at the code below to see if anything is amiss?

Many thanks in advance,
Dan

%============================================================================
% Code: see email from Paul Isambert (2012 August 25 Saturday 2:49pm)
%============================================================================
% Code 1
\newcount\letters
%\newcount\random
\newcount\scratch
\def\endofword{\endofword}

\def\scramble#1{%
  \letters=0
  \countletters#1\endofword
  \extractletters{#1}%
  }

\def\countletters#1{%
  \unless\ifx #1\endofword
    \advance\letters 1
    \expandafter\countletters
  \fi
  }

\def\extractletters#1{%  see email from Paul Isambert (2012 August 26
Sunday 8:55pm)
  \def\rest{}%
  \ifnum\letters>1
    \chgrand[first=1,last=\letters]%   <--edit
    \rand%                             <--edit
    %\setrannum{\random}{1}{\letters}%   <--previous
    \advance\letters-1 \scratch=1
    \getletter#1\endofword%
  \else
    #1%
  \fi
  }

\def\getletter#1{%
  \ifnum\scratch=\value{rand}%  <--edit
    #1%
    \expandafter\getrestofword
  \else
    \advance\scratch 1
    \edef\rest{\rest#1}%
    \expandafter\getletter
  \fi
  }

\def\getrestofword#1\endofword{%
  \expandafter\extractletters\expandafter{\rest#1}%
  }

%\scramble{scramble}
% End of code 1


On Sun, Aug 26, 2012 at 8:55 PM, Paul Isambert <zappathustra at free.fr> wrote:
> Reinhard Kotucha <reinhard.kotucha at web.de> a écrit:
>>
>> On 2012-08-26 at 08:46:26 +0800, Daniel Greenhoe wrote:
>>
>>  > Hi Paul,
>>  >
>>  > Thank you for the source code. I use XeLaTeX and I tried your "Code
>>  > 1". But it said that
>>  >   \pdfuniformdeviate
>>  > was undefined. Is \pdfuniformdeviate only defined in PDFTex? Is there
>>  > some workaround for XeTeX?
>>
>> XeTeX is based on Knuth's TeX and thus doesn't inherit pdfTeX
>> extensions.
>>
>> Maybe you can use Donald Arseneau's random.tex package instead of
>> \pdfuniformdeviate.
>
> Indeed you can "\input random.tex" at the beginning of your document and
> replace \extractletters in my original code with this new definition:
>
>     \def\extractletters#1{%
>       \def\rest{}%
>       \ifnum\letters>1
>         \setrannum{\random}{1}{\letters}%
>         \advance\letters-1 \scratch=1
>         \getletter#1\endofword%
>       \else
>         #1%
>       \fi
>       }
>
> Best,
> Paul
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org



More information about the texhax mailing list