How can i create a random number distribution (FORTRAN)

In summary: ERE that returned a vector of (x,y,z) coordinates if you passed in the center of a sphere.In summary, to create a random distribution of points in the unit sphere, you need to generate three uniform numbers, treat them as coordinates on the sphere, and generate an angle uniformly between 0 and 2pi.
  • #1
sketos
56
0
Hello,

I am working on the two point correlation function in dark matter haloes.

Right now i need to create an array of rundom numbers to compute the estimators.

My question is:

How can i create a random distribution of points in the unit sphere (having in mind its curvature).

I want an array of random numbers 3071 rows, and the random numbers should be in the interval (5,29).

how can i do this?
(and every time i ran it a new distribution of points should arrise.)
 
Technology news on Phys.org
  • #2
There are many ways to do this, and it will depend on details of your calculation which one is best (I don't understand what your numbers mean).

a) Generate three uniform numbers [-1,1], treat them as coordinates (x,y,z), if the point is inside the sphere consider this as a vector, normalize it and you get coordinates on the sphere.
b) Generate an angle uniformly between 0 and 2pi, generate the second angle with the right probability distribution
... google should find many more methods.
 
  • #3
you mean you don't know how to do it? or you don't know how to do it in Fortran? either way this is something a google search should return lots of hits...typically random number generators return a number between 0 and 1 and it is up to you to turn it (proportionally) into the corresponding number within your desired range.

As far as 3071 rows...well, you need to do it 3071 times.

As far as different set every time...well, do not hard set the seed to the random number generator, retrieve the time, instead and use it.

As far as Fortran...google "fortran random" ...it should get hits where you will learn the names of the Fortran intrinsic functions for random number stuff.
 
  • #4
gsal said:
typically random number generators return a number between 0 and 1 and it is up to you to turn it (proportionally) into the corresponding number within your desired range.

That is only half the issue. The other half is getting a uniform distribution of points over the area of the sphere (if that is what the OP meant by "a random distribution having regard to the curvature".

For eaxmple if you take x as a uniform random variable between -r and r, the y as a uniform random varuable between ##\pm\sqrt{r^2 - x^2}## and then calculate ##z = \pm\sqrt{r^2 - x^2 - y^2}## with a randomly chosen sign, you will NOT get a uniform distribution over the area. MFB's method looks right. The step "if the point is inside the sphere ... " is important!
 
Last edited:
  • #5
I used an imsllib (IMSL Library) a few years ago that had a subroutine called RNSPH
 

Related to How can i create a random number distribution (FORTRAN)

1. What is a random number distribution?

A random number distribution refers to the pattern or sequence in which random numbers are generated. It determines the likelihood of certain numbers appearing and the overall randomness of the sequence.

2. Why would I want to create a random number distribution in FORTRAN?

Creating a random number distribution in FORTRAN allows you to generate random numbers that follow a specific pattern or distribution. This can be useful for simulating real-world scenarios and testing the randomness of algorithms.

3. How do I create a random number distribution in FORTRAN?

To create a random number distribution in FORTRAN, you can use the built-in function RAND(), which generates a random real number between 0 and 1. You can then use this function in combination with other mathematical operations to create a desired distribution.

4. What types of random number distributions can I create in FORTRAN?

FORTRAN allows you to create a variety of random number distributions, such as uniform, normal, exponential, and Poisson distributions. You can also customize the distribution by adjusting the parameters of the function used to generate the random numbers.

5. Can I control the randomness of the distribution in FORTRAN?

Yes, you can control the randomness of the distribution in FORTRAN by adjusting the seed value of the RAND() function. The seed value determines the starting point for the random number sequence, so changing it can lead to different distributions or patterns in the generated numbers.

Similar threads

  • Programming and Computer Science
Replies
1
Views
659
  • Programming and Computer Science
Replies
10
Views
3K
Replies
25
Views
3K
  • Programming and Computer Science
Replies
4
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
15
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
429
  • Programming and Computer Science
Replies
7
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top