How can i create a random number distribution (FORTRAN)

Click For Summary

Discussion Overview

The discussion revolves around generating a random number distribution within a unit sphere, specifically for use in calculating the two-point correlation function in dark matter haloes. Participants explore methods for creating an array of random numbers within a specified range and ensuring a uniform distribution over the sphere's surface.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks guidance on generating an array of random numbers within the interval (5,29) that represents points in a unit sphere.
  • Another participant suggests generating three uniform numbers in the range [-1,1] and normalizing them to obtain coordinates on the sphere.
  • Alternative methods are proposed, including generating angles uniformly and using appropriate probability distributions for the second angle.
  • A participant notes that random number generators typically produce numbers between 0 and 1, and emphasizes the need to scale these numbers to the desired range.
  • Concerns are raised about achieving a uniform distribution of points over the sphere's surface, with a specific example provided to illustrate potential pitfalls in uniformity.
  • A reference to using an IMSL Library subroutine called RNSPH is mentioned as a possible resource.

Areas of Agreement / Disagreement

Participants express differing views on the best methods for generating random points within a sphere and achieving uniform distribution, indicating that no consensus has been reached on a single approach.

Contextual Notes

There are unresolved issues regarding the assumptions necessary for achieving uniformity in point distribution and the specific requirements of the participant's calculations.

sketos
Messages
55
Reaction score
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
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.
 
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.
 
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:
I used an imsllib (IMSL Library) a few years ago that had a subroutine called RNSPH
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
19
Views
2K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K