Re: random number generator
Eric Blake <[email protected]>
| Newsgroups | gmane.comp.gnu.m4.general |
|---|---|
| Organization | Red Hat |
| Message-ID | <[email protected]> |
On 08/18/2010 11:25 AM, mikeyzman wrote: > > Im having trouble generating random numbers with M4. I found a thread on the > subject but the recommended defs do not work > >>> m4 lacks a random number generator builtin. I think it would be great if > such builtin existed. Currently I use something like: > dnl random(num): Evaluates to a random number from range 0..num-1. > define([random],[eval(esyscmd(printf $RANDOM) % $1)])dnl What is your /bin/sh? $RANDOM is a bash extension, and if your /bin/sh is dash, that would explain why you are not passing any argument to printf. You can modify your esyscmd to force bash: esyscmd([/bin/bash -c 'printf "$RANDOM"']) -- Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
(application/pgp-signature, 619 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMbBkQAAoJEKeha0olJ0Nq/7AIAKOA6NYJZBIE0GnBBg4wfmqr DbaIezXkrHNwdLw5D1NKUNEBpcSTCV2U1pp+Ps86ohgvU9vK+QYZ9femaNqF7ptr elPqNyftuVru0qRvOVxX5NJKbmIc9x0dAumCcAUVdqqKkRcainWBMQsS2Goe72x6 8SgIzVCOvGw5BcjcSaR5SBJ585bFHzrXHlECt8MG5YDj5dVM3uNQ5Cr2jum5KhDn M4ZGgam2oPKaKhPkvTNB4n6QMoZmbQANQ91VpuHOFuApte7/ZWkBD7YwNPMb6m4w 7fQ7EFR9J/i6LaygICJDfB2l3e2OxZMt/WMFZY1WYMeYWuZvaXso7OczDlRMwdM= =0AET -----END PGP SIGNATURE-----