TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to generate a "word cloud" by using \mboxes with random spaces around words.

In the code below I've removed stuff that change the font size, and I've replaced \mboxes by \frameboxes for debug purpose.


\usepackage[first=1, last=10]{lcg}





When I replace length with \rand (i.e. \vspace{\rand pt}), I get the following error:

! Illegal unit of measure (pt inserted).

Does anyone know how to fix this error?

And why the \rand at the beginning of the document doesn't print anything?

Is there a better way to produce a word cloud?

share|improve this question

The manual of the lcg package states:

Each call of the command \rand will write a new random number to the counter provided by the user with the key [=package option] counter or to the standard counter of this package rand. Now it's possible to do whatever can be done with counters.

So \rand is not expanding to a number and therefore doesn't typeset anything and can't be used in a length. You need to use it first and then can use the rand counter using \value{rand}, e.g. \vspace{\value{rand} pt}.

You could also use the math engine of the pgf package. It provides \pgfmathrandom{x,y} (also accessible using \pgfmathparse{random(x,y)} and friends) and stores the result into \pgfmathresult. Here x and y are the same numbers as first and last with lcg.

% ...
\vspace{\pgfmathresult pt}

% or even
share|improve this answer

In the documentation for lcg, it says

Each call of the command \rand will write a new random number to the counter provided by the user with the key ⟨counter⟩ or to the standard counter of this package—rand.

To get the value stored in the counter rand use \therand. So,

\vspace{\therand pt}

will work.

share|improve this answer
Right, \therand works as long it has its original meaning of \arabic{rand} which uses \number internally. I personally prefer \value{rand}, which is more efficient (not that it counts much). However, \therand might be saver for normal LaTeX users because \value{rand} exposes the counter register directly and would cause an error if used in-text on its own. – Martin Scharrer Apr 27 '11 at 17:47
Thank you very much, it works now :) – bob Apr 27 '11 at 20:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.