Random number generation
I am using the random number generator functions (rand and srand) to generate random numbers.
The numbers are used to generate a random terrain.
If I seed the the random numbers using a known seed (using srand) will the random numbers generated aways be the same across all windows platforms (win95, 98 etc..)? It always appears to generate the same results on 2000.
I am planning to use this for a multiplayer network game to ensure all of the terrains across the computers are identical.
thanks for the Help
Gavin.
I am using MS Visual Studio .NET as the compiler
> If I seed the the random numbers using a known seed (using
> srand) will the random numbers generated aways be the same
> across all windows platforms (win95, 98 etc..)? It always
> appears to generate the same results on 2000.
Don''t know. And if I don''t know I roll my own.
The source for rand is simple and widely available, & you can just use a version of it in your own code. This has the advantages:
- more easily debuggable
- easy to try substitutes (as standard rand() has some known problems)
- can produce much faster code, as it is short enough to be inlined
- avoids nasty problem where your use of rand() is influenced by someone elses, e.g. if someone calls it from a library or in sample code you use.
As long as you stick to integer arithmetic you can produce code that works identically on all imaginable game platforms.
> srand) will the random numbers generated aways be the same
> across all windows platforms (win95, 98 etc..)? It always
> appears to generate the same results on 2000.
Don''t know. And if I don''t know I roll my own.
The source for rand is simple and widely available, & you can just use a version of it in your own code. This has the advantages:
- more easily debuggable
- easy to try substitutes (as standard rand() has some known problems)
- can produce much faster code, as it is short enough to be inlined
- avoids nasty problem where your use of rand() is influenced by someone elses, e.g. if someone calls it from a library or in sample code you use.
As long as you stick to integer arithmetic you can produce code that works identically on all imaginable game platforms.
John BlackburneProgrammer, The Pitbull Syndicate
Probably they will be same as long you use the same executeable, but I wouldn''t rely on it.
You never know how those library functions are implemented, they can suddenly change on windows2015 or whatever.
Also they will probably change if you use another compiler.
The best solution will be you write your own random number generator or use one of those that can be found in the net.
As that pice is completly in your code you have complete control over it, and you even rely it will be "constant random" even over different platforms.
You never know how those library functions are implemented, they can suddenly change on windows2015 or whatever.
Also they will probably change if you use another compiler.
The best solution will be you write your own random number generator or use one of those that can be found in the net.
As that pice is completly in your code you have complete control over it, and you even rely it will be "constant random" even over different platforms.
-----The scheduled downtime is omitted cause of technical problems.
This should be in the general programming forum; you''d have a better chance of getting a good answer there.
I don''t know either, but I think that it will probably always be the same. Use boost if you are not sure.
Cédric
I don''t know either, but I think that it will probably always be the same. Use boost if you are not sure.
Cédric
It''s not part of the library spec that the same seed produces the same output when you switch library versions (wouldn''t have anything to do with the OS, BTW) so you have to assume it could be either different or the same--that is, you can''t count on getting the same output, and you can''t count on getting different output. Roll your own.
OTOH, even if it''s not part of the spec, I don''t see how it could be different from one computer to another. It''s a pseudo-random number generator. It is not going to use a special "rnd" function if it is supported by the processor.
Cédric
Cédric
The rand function in mingw32 returns a signed 16-bit integer whereas the rand function in gcc returns a signed 32-bit integer.
SpiffGQ
quote:
Original post by cedricl
OTOH, even if it''s not part of the spec, I don''t see how it could be different from one computer to another. It''s a pseudo-random number generator. It is not going to use a special "rnd" function if it is supported by the processor.
Different versions of a library may use different constants or a different algorithm altogether, thus changing the output for a given seed.
If you''re using the CRT as a shared library (i.e. DLL) then you''d be insane to assume the outputs will be the same. If you using it as a static library, then that assumption isn''t as bad...
If I had my way, I''d have all of you shot!
codeka.com - Just click it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement