473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Random number generation from functions

drs
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.

thanks,

-d
Jul 18 '05 #1
5 2323
On Mon, 29 Nov 2004 20:51:50 GMT, "drs" <dr*@remove-to-send-mail-ecpsoftware.com> wrote:
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.

thanks,

Don't know what you mean. This kind of thing?
(the 1-random... is to make the random numbers in (0,1] instead of [0,1))
import random
import math
math.log(1.0-random.uniform(0,1)) -0.90030288455841156 math.log(1.0-random.uniform(0,1)) -0.261249141864835 math.log(1.0-random.uniform(0,1))

-0.99694366818547997

Regards,
Bengt Richter
Jul 18 '05 #2
drs wrote:
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.

thanks,

-d

numarray has a random package which provides a number of functions,
including: normal( mean, stddev, shape=[])

That may serve your need.

Colin W.
Jul 18 '05 #3
drs wrote:
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.

thanks,

-d

I remember for having used it on a gaussian generator that you can do that very
easily by yourself:
- you generate a random real number in the range [0 .. 1],
- then you apply an inverse probability density function (e.g. inverse gaussian
pdf : http://www.itl.nist.gov/div898/softw...ar/rigpdf.htm),
and you have then your random number following the specified law (here gaussian).
Jul 18 '05 #4
drs wrote:
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.


scipy[1] has a large collection of "standard" univariate pdfs, including
normal, exponential, gamma, and the like.

One cannot generate random numbers from arbitrary real valued functions
because a function needs to satisfy certain restrictions to be a pdf.
For example, you cannot generate random numbers "with a log function",
unless you restrict the domain and renormalize.

Generating random numbers from an arbitrary pdf is possible, but tricky.
I encourage you to search the literature for "monte carlo sampling."

[1] http://www.scipy.org

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #5
On Mon, 29 Nov 2004 20:51:50 GMT, "drs"
<dr*@remove-to-send-mail-ecpsoftware.com> wrote:
Is there any way to generate random numbers based on arbitrary real valued
functions? I am looking for something like random.gauss() but with natural
log and exponential functions.


Try with CRNG, it may have what you need, or be able to adapt it to
what you want. http://www.sbc.su.se/~per/crng/

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brandon Michael Moore | last post by:
I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a...
6
by: Diodak | last post by:
**************************************** How can get RANDOM record from XML file? **************************************** for e.g. in xml files i have aprox.200 records. how get random position...
3
by: Mike Brown | last post by:
I have questions about thread safety in the 'random' module. When using the random.Random class (be it Mersenne Twister or Wichmann-Hill based), is it sufficiently thread-safe (preserving entropy...
10
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
7
by: moni | last post by:
Hi, Can anyone tell me , how I would generate random numbers, for an interval say from 15 to 450 in C. Plz lemme know. thanx..
22
by: gagan.singh.arora | last post by:
Hi there. I want to generate random numbers with a given probability, say 80% even and 20% odd. Is it possible to implement such an algorithm in C?
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.