The Source for Java Technology Collaboration

Home » java.net Forums » The Big Question » The Big Answer

Thread: Beginner Question

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 3 - Last Post: Jul 9, 2007 12:01 AM by: jwenting Threads: [ Previous | Next ]
luft

Posts: 1
Beginner Question
Posted: Jul 4, 2007 11:41 AM
 
  Click to reply to this thread Reply

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.

klopperq

Posts: 14
Re: Beginner Question
Posted: Jul 5, 2007 5:13 AM   in response to: luft
 
  Click to reply to this thread Reply

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

Posts: 10
Re: Beginner Question
Posted: Jul 5, 2007 11:44 AM   in response to: klopperq
 
  Click to reply to this thread Reply

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

Posts: 478
Re: Beginner Question
Posted: Jul 9, 2007 12:01 AM   in response to: erickson
 
  Click to reply to this thread Reply

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.




 XML java.net RSS