Boost logo

Boost-Build :

Subject: Re: [Boost-build] Generating random number string in b2
From: Ryan Gonzalez (rymg19_at_[hidden])
Date: 2016-10-10 16:31:33


FWIW, I just wrote a module for random numbers, because I'm a horrible
sadist (only works on Unix system, BTW, and not Solaris):

import "class" : new ;
import numbers ;
import regex ;

local rule time ( ) {
    local time = [ SPLIT_BY_CHARACTERS [ SHELL "date +%s%3N" ] : "\n" ] ;
    return $(time[0]) ;
}

local rule mul ( a b ) {
    local res = 0 ;
    for local _ in [ numbers.range 1 $(b) ] {
        res = [ CALC $(res) + $(a) ] ;
    }
    return $(res) ;
}

local rule mod ( a b ) {
    while [ numbers.less $(b) $(a) ] {
        a = [ CALC $(a) - $(b) ] ;
    }
    return $(a) ;
}

local rule trimtime ( time ) {
    return [ regex.match "(.....|....|...|..|.)$" : $(time) : 1 ] ;
}

local rule tostate ( x ) { return [ mod $(x) 101 ] ; }

state = [ tostate [ trimtime [ time ] ] ] ;

rule random ( ) {
    state = [ tostate [ mul $(state) 7 ] ] ;
    return [ CALC $(state) - 1 ] ;
}

On Mon, Oct 10, 2016 at 10:07 AM, Edward Diener <eldiener_at_[hidden]>
wrote:

> Is there a way to generate a random number string in b2 ?
>
> I have a rule which may be invoked more than once with the same parameters
> from a jam file. The rule creates build targets based on the parameters and
> I need to give each build target a unique name. Of course it would be nice
> if the end-user invoked the rule with the same parameters only once in a
> jamfile and saved the result in a local variable but I cannot force that
> usage. Therefore I want to generate a uniquely named build target even when
> the parameters to the rule are the same. I am using configure.builds with
> the build target so as long as my uniquely named build target matches what
> is passed to configure.builds I am OK.
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman
> /listinfo.cgi/boost-build
>

-- 
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk