Skip to main content

Beginner Question

3 replies [Last post]
luft
Offline
Joined: 2007-04-28

I'm just starting my journey into the world of Java programming and I'm finding myself a bit overwelmed. I'm using the NetBeans IDE to learn Java (On Ubuntu Linux) and am VERY impressed.

In order to learn the language I have decided to work on a fun project with no real world usefulness. I want to create a map generator to generate terrain data. I wanted to use a random number generator like Util.Random that accepts a seed number so that the map could be reliably reproduced simply by knowing the seed value. This is so that large map sectors could be regenerated when needed thus saving huge amounts of disk space.

I got to thinking however that if future versions of Random produce different numbers my map generator wouldn't be very good.

Is this a likely problem or are the numbers generated for a particular seed pretty reliable going into the future. What about on different platforms? Linux, OSX, Windows.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
klopperq
Offline
Joined: 2005-09-23

Hi

This is a comment from the javadoc for java.util.Random ...

"If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code."

It is clear from this that your software should work across different JVM implementations/ platforms. Im not however sure if this guarantees "future proofing" of your code...

erickson
Offline
Joined: 2004-07-07

I would say that one can rely on this contract to provide "future proof-ness" too. When the implementation is spelled out like that, another class would have to be created to provide a different algorithm.

jwenting
Offline
Joined: 2003-12-02

unless of course the specification changes, but if you have to account for that all bets are off and you should really write your own language and compilers to run on your own operating system that works on top of your own hardware built in your own factories using raw materials from your own mines.
Hardly appropriate for most applications.