[Numpy-discussion] numarray.random_array number generation in C code

Faheem Mitha faheem at email.unc.edu
Tue Oct 5 15:44:36 CDT 2004


On Tue, 5 Oct 2004, Bruce Southey wrote:

> Hi,
> It is rather hard to suggest anything without more detail on what you want to
> actually do.

I could give you more details if you were interested.

> As you describe it, why do you need the 'seed' returned? It would only 
> make sense if you were going in and out of Python multiple times - a 
> somewhat undesirable situation due to the overhead costs.

Not really. One might (and I frequently do) want to run the same function 
(which in this case might be all in C++ code), interactively with 
different parameters. The kind of thing that I'm doing is akin to 
exploratory data analysis, and the specific code in question is a 
stochastic search algorithm. Doing all this in C++ would not be very 
interactive. Also, one often wants to postprocess data output using Python 
scripts. This involves multiple calls to C++ code, and would be impossible 
to do using C++, since one has to call other Python libraries.

  > I see at least three options:

> 1) Do everything in Python/numarray.

That's my current situation.

> 2) Do parts in Python and the other in C/C++.
>   For example, pass a matrix of random numbers to your code from Python. The
> 'seed' never needs to leave Python.

This doesn't work very well unless you know in advance how many random 
numbers are needed (not the case, for example, for stochastic search 
algorithms), and in any case is a rather clumsy way to do things. No 
offense intended.

> 3) Do it all in C/C++ - pass the 'seed' into your code that includes the
> random number generator(s) - there is C/C++ code around for this. Do you stuff
> and then return the 'seed' back with whatever else is required.

Yes, but part of the point of mixed programming is that you have an 
interpreted front end which can easily hook into other routines. Also, in 
this case, you would not be passing the seed in, since there is nothing to 
pass it in from. One would simply call system time or something similar to 
obtain the seed.

> You can email me privately if you want.

I'll keep sending this to the list unless someone objects, since I think 
this is of some general interest.

Really, my main question was to whether my understanding of how to use the 
Numarray random number facilities in C was correct or not.

                                                                Faheem.




More information about the Numpy-discussion mailing list