Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (794)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Roquen's Random Number Generators...  (Read 1480 times)
0 Members and 1 Guest are viewing this topic.
Offline princec

« JGO Spiffy Duke »


Medals: 1096
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Posted 2019-04-03 13:59:04 »

As found here:

https://github.com/roquendm/JGO-Grabbag

@Roquen of these parts (haven't seen 'em for a while...) has some decent implementations of pseudo random number generators. In particular I've lately switched from LCR64 to XorShift64 in my terrain generation as it gives veeeery slightly more pleasing results... provided you've got a lot of bits set in your seed. It turns out that using the map index as a seed (essentially an integer sequence starting at zero) gives a very poor initial random number from XorShift64 - it takes quite a few reads to get a decent number of bits to start twiddling, and you can end up with a very not-at-all-random looking sequence of numbers for quite some time.

To fix this I've updated my setSeed() function to make a Wang hash of the incoming seed, which means inadvertently using a sequence of small integers with few bits in won't result in terribly obvious artefacts when reading the initial series of numbers.

Here's a Wang hash, with a handy link to the source of this implementation:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   /**
    * Wang hash. See <a href="http://www.burtleburtle.net/bob/hash/integer.html">here</a> for details.
    * @param value
    * @return a hash of the value
    */

   public static int wang_hash(int value) {
      value = (value ^ 61) ^ (value >>> 16);
      value *= 9;
      value = value ^ (value >>> 4);
      value *= 0x27d4eb2d;
      value = value ^ (value >>> 15);
      return value;
   }


Cas Smiley

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (3162 views)
2018-11-16 13:46:03

hadezbladez (1145 views)
2018-11-16 13:41:33

hadezbladez (3131 views)
2018-11-16 13:35:35

hadezbladez (625 views)
2018-11-16 13:32:03

EgonOlsen (3913 views)
2018-06-10 19:43:48

EgonOlsen (4389 views)
2018-06-10 19:43:44

EgonOlsen (2618 views)
2018-06-10 19:43:20

DesertCoockie (3437 views)
2018-05-13 18:23:11

nelsongames (3559 views)
2018-04-24 18:15:36

nelsongames (4609 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!