Small step random number generator

3 Ansichten (letzte 30 Tage)
Jim
Jim am 28 Apr. 2014
Bearbeitet: Image Analyst am 28 Apr. 2014
Hi I need a random number generator which generates a random number between 0 and 1. The generator has to produce values as small as 1e-13. Currently I am using a vector,
vec=0:1e-13:1
where I get random numbers from. This process is very slow and time consuming as you can imagine. Does anyone know a better alternative ?
  2 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 28 Apr. 2014
This is not clear, random number between 0 and 1? or small numbers?
dpb
dpb am 28 Apr. 2014
Stratified sampling, mayhaps?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 28 Apr. 2014
Bearbeitet: John D'Errico am 28 Apr. 2014
The existing RNG produces numbers that small, and smaller. Admittedly, the probability of getting any such value is small, but that is the nature of a random generator.
Why are you doing something as insane as this? Do you realize that simply generating a vector of that obscene length will take a huge amount of time? Sorry, but your method is completely insane.
For example, consider how many elements the vector 0:1e-13:1 has in it. A simple computation tells us it has 1+1e13 elements. Stored as doubles, each element will require 8 bytes,
8*1e13/2^40
ans =
72.76
so approximately 73 terabytes of RAM. As I said, insane. Read the help for rand.
doc rand
Perhaps you want numbers on a log scale, or something like that. Or maybe you want some variety of discrete RNG, quantized at that level. If so, then be clear about your goals. Even if those are your goals, there are far easier ways to do so.
  1 Kommentar
Image Analyst
Image Analyst am 28 Apr. 2014
Bearbeitet: Image Analyst am 28 Apr. 2014
Jim's "Answer" moved here because it's a comment to John, not an answer to the initial question:
Dear John, I know that my current matlab script is insane, I am currently creating a vector with steps of 1e-9 (can't go any bigger because of a lack of memory). I need these randoms numbers to sample a user defined distribution function. The distribution function I have is normalized so I need to produce random numbers between 0 and 1. The idea is that I fill 3D space with for example ten million random points, all the points that lay beneath my distribution function are taken into account while all the other points are deleted. The distribution function has a exponent with a negative terms so it drops to really low values.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by