Some time ago I used a seq-like tool for printing a sequence of pseudo random generated numbers to stdout. You could specify a range, seed, and the number of samples and much more.

I've just forgotten the name of this tool. Can anyone help me out?

Perhaps you know even a more advanced tool that, for example, supports different probability distributions or even the generation of a sequence of random words under different alphabets and length/character distributions.


Do you mean jot?

$ jot 
jot: jot - print sequential or random data
usage:  jot [ options ] [ reps [ begin [ end [ s ] ] ] ]
    -r      random data
    -c      character data
    -n      no final newline
    -b word     repeated word
    -w word     context word
    -s string   data separator
    -p precision    number of characters

If you use Ubuntu the package is athena-jot. A simple example:

$ jot -r 10 12 27


| improve this answer | |
  • yes, jot was that command, thanks! Again,I appreciate further suggestions of more advanced sequence generating tools. – maxschlepzig Aug 25 '10 at 10:13

If you don't mind writing a small script to do what you need, I'd recommend doing it in R, the open-source statistics system.

For instance, consider this one-liner to get a list of 100 Gaussian-distributed numbers:

$ Rscript -e 'write(rnorm(100) * 100 + 100, "", 1)'

Let's break this down.

The standard R command brings you into an interactive programming environment, which is fine if you're trying to work out how to do something by hand or are building something up incrementally, but from your question, it sounds like you just need a list of numbers to send to another program. So instead, we use Rscript, which behaves more like a traditional Unix script interpreter: you can pass it the name of a file containing an R script, or use the standard -e flag to pass the entire program text on the command line.

rnorm() is the R function to get a list of random numbers with the "normal" or Gaussian distribution. It takes up to three parameters, only the first of which is required, how many numbers you want. We've asked for 100. By taking the defaults for the other two optional parameters, we get a mean of 0 and a standard deviation of 1.

The arithmetic after that is just showing off a cool feature of the R language: you can do arithmetic on whole data tables, matrices, etc., just as easily as a scalar value in a more typical language. I've multiplied all generated values by 100 and added 100 to them, just because I can. Because R is a full-fledged programming language, there's no limit to the things you could do with this list of numbers. That's the advantage of using such a system instead of a fixed-purpose command like jot.

We pass the result of that previous operation to the write() function, which writes the data out to a file by default, but we've overridden that by passing a blank string for the second parameter, the file name, so it writes the table out to the terminal instead. The next parameter, 1, just tells it we want our output in single-column format.

R has many other random number generation functions built into the base system. For instance, we can mimic the jot command in lcpriani's answer with this script:

$ Rscript -e 'write(round(runif(10, 12, 27)), "", 1)'

Here we're using runif() to get 10 uniformly-distributed random numbers from 12 to 27. Like rnorm(), which we used above, this function returns floating-point values, so we have to round() them to their nearest integer values before writing them to the screen.

R also has a rich set of add-ons in CRAN, a package repository modeled on Perl's CPAN. One you might be interested in is simply called random, which acts as an interface to random.org, a service that returns true random numbers generated from atmospheric noise.

R is a complete programming environment, so it may be that you don't actually need to get your numbers out of R in text format. You might be able to solve your problem entirely in R. Give it a shot.

| improve this answer | |
  • What is the R way to get x random numbers from a given interval? E.g. 100 random numbers between 10 and 200 (e.g. from the normal distribution)? – maxschlepzig Aug 28 '10 at 7:33
  • I added info on mimicking lcpriani's jot command to the above answer. As for limiting values for rnorm(), that's not the way the normal distribution works. If you take the default mean of 0 and SD of 1, then 1000 is still a possible return value, it's just exceedingly unlikely. R would let you write something that would clamp the values to remove things outside a given range, but then you'd probably be misusing the normal distribution. – Warren Young Aug 28 '10 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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