Re: [Seed7-users] Q: random number generation
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: Thomas M. <tho...@gm...> - 2012-04-23 08:01:39
|
On Fri, 20 Apr 2012 00:14:36 +0200, mok-kong shen <mok...@t-...> wrote: > Hallo, > > I am a newcomer of the list and wish to know: Is it possible to somehow > obtain in seed7 the functionality akin to e.g. that of SystemRandom of > Python? Do you mean an access to the random number generator of the operating system? AFAICS Python does not guarantee that SystemRandom is available on all operating systems. Seed7 tries to provide APIs that are always available. Besides this problem it would be possible to support such functionality. As quick solution for Linux you could just open "/dev/urandom" and obtain the random values from there. I am not a Python expert. Does SystemRandom plug in its functionality to the standard random function? Is there a class for random generators and SystemRandom is just one of them? The random function of Seed7 (rand) has currently no possibility to plug in a random number generator backend (but this extension could be done). It would also be possible to introduce a randomGenerator interface as backend for 'rand'. In this case there could be a built-in and a system random number generator. The Seed7 function 'rand' is overloaded for many types. Creating an extra function for system random values would also make it necessary to overload it for many types. Therefore I had the idea with a random number generator backend. Probably Python or other languages already have it. I was just too lazy to check. If you are interested in the Seed7 implementation of rand you can look at the function uint_rand in int_rtl.c which is used as hardcoded random number generator backend. The functions intRand, fltRand and bigRand are based on uint_rand. Does this answer your question? Greetings Thomas Mertes -- Seed7 Homepage: http://seed7.sourceforge.net Seed7 - The extensible programming language: User defined statements and operators, abstract data types, templates without special syntax, OO with interfaces and multiple dispatch, statically typed, interpreted or compiled, portable, runs under linux/unix/windows. -- NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone! Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a |