Running a rand or random script

Simon Barner barner at
Mon Jun 16 09:42:46 PDT 2003


> I need to run a script, perhaps using FBSD's 'rand' or 'random' command (or
> any other) that will generate one single 5-digit number 'at random' between
> 00001-99999
> Anyone have thoughts on how to do this....??

Don't know about a shell way to do this, but what about this tiny
C program (compile and link with gcc -c -o r.o && gcc -or r.o)

#include <stdlib.h>
#include <time.h>
int main (int argc, char *argv[]) {
	/* use this on non-BSD systems:
	srandom(time (0));
	unsigned int r = random () % 99999 +1;
	printf ("%d\n", r);
	return r;


More information about the freebsd-questions mailing list