- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
What random number generator are you using?
If you use the same number as a starting seed you will generate the same sequence of psuedo random numbers. (This is useful for testing pruposes)
If you are using theinbuiltRANDOM_NUMBER then, from the help :
"The seed for the pseudorandom number generator used by RANDOM_NUMBER can be set or queried withRANDOM_SEED. If RANDOM_SEED is not used, the processor sets the seed for RANDOM_NUMBER to a processor-dependent value."
You could use something like getting the current date ∨ time and using that to calculate anumber to set the seed.
Les
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Robert
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
However, I am willing to try if there are inbuilt subroutines that I could use and get a dynamic random number. I have no idea how to go about it though. Please advice.
Thanks.
Pappu Murthy
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I found all about Rand and how to use it. BUt it is still not clear what I need to do (exact statement please), to get totally random sequence of numbers everytime I call. I am not getting the same sequence of numbers everytime i execute the program.
Thanks
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
If you want the same sequence every time you run the program, then either don't call RANDOM_SEED or call it with a specific seed value at the program start, then call RANDOM_NUMBER to get values.
If you want a different sequence every time, call RANDOM_SEED with no arguments at the program start and then use RANDOM_NUMBER to get values.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
real(4) ranval
call Random_seed ()
ranval2 = random(0) ! get next random number
ranval3 = random(0)
ranval4 = random(0)
ranval5 = random(1)
print *, ranval2,ranval3,ranval4,ranval5
end
The anpve os ,u cpde amd ot does not work. What am I doing wrong?
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
[fortran]real(4) ranval(4) call random_seed call random_number(ranval) print *, ranval end[/fortran]If you want separate scalar variables, then declare each of the "ranval" variables and call random_number (not "random") for each variable. random_number is a subroutine, not a function.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I tried to copy my screen using the Snipping tool but that is not working. So you just have to believe my words.
I ran like a dozen times the same program and noticed atleast three or 4 times the same 4 numbers (identical to last digit) were produced. This is strange or may be there is a bug.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I modified the program to add:
call sleepqq(1000)
before the call to random_seed, and this eliminated the duplicate sequence. This call waits one second.
[plain]C:Projects>r.exe 0.5473583 0.6576169 0.1448505 0.2380749 C:Projects>r.exe 0.2513333 0.9547036 0.3125785 0.6219466 C:Projects>r.exe 0.3072958 0.4003339 6.4170554E-02 0.6977542 C:Projects>r.exe 0.3632583 0.8459641 0.8157625 0.7735617 C:Projects>r.exe 0.4192208 0.2915944 0.5673546 0.8493693 C:Projects>r.exe 0.1231958 0.5886813 0.7350826 0.2332410 C:Projects>r.exe 0.1791582 3.4311488E-02 0.4866747 0.3090485[/plain]
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
But that is one part of the story. The other part is this: the Fortran standard tells us that in case RANDOM_SEED is called without any argument, the seed is set to a processor-dependent value. Intel organised this in such a way that different calls to RANDOM_SEED causes that different sequences are obtained. But there is no guarantee that other compilers follow the same way. There is a risk that (any of) these compilersgenerate an equal seed for every call of RANDOM_SEED. So, if you want to write portable software, I suggest you to consider the use of an explicit setting of the put-argument as suggested by some of the contributants of this thread.
Robert
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Pseudo-random number generator is the algortihm for producing the sequence of numbers that look like random and follow some specific stat properties.To start generation of the random numbers you will need to initialize the algorithm with a start value, "seed". If you provide the same seed you will always obain the same sequence of thenumbers. To make sure that each run of your codeis supported with a new sequence of random numbers you will need to initializeyour generator with a new seed.The new seed can be obtained by some "external tools" likea physicalsource of random numbers or system counters.
Please, have a look at the article available at http://software.intel.com/en-us/articles/initializing-Intel-MKL-BRNGs/. While thiscommunication is about initialization of Random Number Generators in Intel Math Kernel Library some of the aspects listed thereareapplicable to random number generators availablein the compiler.
Thanks,
Andrey
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable