I am kind of new in the fortran proramming. Can anyone please help me out with the solution. i am having a problem of generating integer random number in the range [0,5] in fortran random number using random_seed and rand
相关问题
- Do the Java Integer and Double objects have unnece
- CABS(x) function for complex(8)
- Unity - Get Random Color at Spawning
- How do I merge consecutive numbers in a sorted lis
- How to generate a random number, then display it o
相关文章
- why 48 bit seed in util Random class?
- Does gfortran take advantage of DO CONCURRENT?
- Need help generating discrete random numbers from
- Get random records with Doctrine
- Fortran 90 - “Segmentation fault - invalid memory
- Looking for a fast hash-function
- regular expression to add characters before and af
- Oracle random row from table
What about:
To support the answer by Alexander Vogt, I'll generalize.
The intrinsic
random_number(u)
returns a real numberu
(or an array of such) from the uniform distribution over the interval [0,1). [That is, it includes 0 but not 1.]To have a discrete uniform distribution on the integers {n, n+1, ..., m-1, m} carve the continuous distribution up into m+1-n equal sized chunks, mapping each chunk to an integer. One way could be:
As you can see, for the initial question for {0, 1, 2, 3, 4, 5} this reduces to
and for the other case in your comment {-1, 0, 1}
Of course, other transformations will be required for sets of non-contiguous integers, and one should pay attention to numerical issues.