m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: random number generator


From: Eric Blake
Subject: Re: random number generator
Date: Wed, 18 Aug 2010 11:32:00 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.1.1

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   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]