[Top][All Lists]

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

Re: random number generator

From: mikeyzman
Subject: Re: random number generator
Date: Wed, 18 Aug 2010 10:44:52 -0700 (PDT)

Thanks for the response

I put in a $SHELL call so you can see what is going on:
esyscmd(`printf $SHELL')dnl
esyscmd(`printf $USER')dnl
esyscmd(`printf $RANDOM')dnl


printf: 1: usage: printf format [arg ...]

So I tried your suggestion, standalone (esyscmd([/bin/bash -c 'printf

and here is my output:

sh: [/bin/bash: not found
m4: esyscmd subprocess failed

Im running M4 on Ubuntu, I don't know if that matters, I apt-got M4 the
other day so Im sure its recent.  BTW I used M4 for years at a former
company, but Im not familiar with the [] notation.  It seems to me they are
the same as start and end ticks?  (`')


Eric Blake-3 wrote:
> 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

View this message in context: 
Sent from the Gnu - M4 - Discuss mailing list archive at Nabble.com.

reply via email to

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