Java 2D OpenGL RPG Tutorial 10: Random Number Generator Improvements

preview_player
Показать описание
This video discusses a different approach to random number generation and implements the WELL512 version of the WELL algorithms.
Рекомендации по теме
Комментарии
Автор

Please make more of these, you have inspired me to make Java games again. A door would be nice :)
Thanks, Tom

cateriq
Автор

Thank you for provide nice tutorial to us every time :)

rsBaker
Автор

EDIT: All numbers given below in relation to time are based on the algorithm as written in this video.

After a whole lot of additional research into this topic since I first saw this video (before I started watching the others), no, no java.util.Random is not really bad. It's not as fast as it could be, but it's still very fast, and likely not going to be the source of slowness in any game you make. It has a period of 2^48 (281~ trillion), which, while not as good as it could be, will suit an RPG just fine. Especially considering the maximum amount of time an RPG will typically be running is a couple of hours, maybe as much as a day straight, it's really not a concern. Whether you'd want to implement your own while working on any project relies largely on what you desire, and it's really well outside the scope of these tutorials. Something perhaps demonstrated by the complete lack of actual discussion of the topic in the prior comments.

Given this, I strongly disagree with your choice of including this material in the series of tutorials.

That said, I'm personally quite happy with this, and find it useful as I have an atypical interest in the subject given the general audience who will be here, and while I disagree with the video's placement, I am quite happy to have obtained more resources in terms of PRNGs, as I've a few I've already looked into and coded up for my own purposes.

static blocks like that aren't really meant for simple initialization. You should just leave it as:

private static long[] state = new long[16];
private static int index = 0;

The reason static blocks exist is basically so you can do complex stuff. The reason you couldn't do private static long state[16] is because you're attempting to set the size of the array Type rather than the array "Object" you're creating.

Also, I found that the way we've implemented the WELL512 alg (as a subclass of Random, which I agree with), it's actually about twice as slow as java.util.Random itself. The only place I got it faster was when generating Longs, and only there because I ignored the next() method and plugged it directly into the generation alg. So, you could say that WELL512 is actually significantly slower in terms of non-critical PRNGs.

If you have a good argument for exactly why you need better properties than Java.util.Random in your game, feel free to offer them.

EDIT:
The method I use when I need lots of seeds is to just create a normal Random class. It seeds itself based on the time by default, or you can toss in a single int seed and use that. Gets you out a bunch of different numbers without much effort.

I will say your method of providing a single int seed to something that has a 16-long state is kind of weird though. You really should be letting people set the 16 longs.

This is how you could have resolved that:

this(new Random().nextInt());

seigeengine
Автор

I just found your channel. A lot of useful videos. Good job !

Just a recommendation: why don't you increase font size?? :)

ZeKalanga
Автор

Benny, instead of typing every time System.out.println();
you can simply type "SOUT" and then press TAB

TheWeatherManFtw
Автор

Do you remember how to get up the list of shortcuts?
Also, for anyone else "psvm" TAB gives the main method header

HyperOneGlove
Автор

Hey Benny, how about you add some graphics next? Maybe even with some animation for attacking and moving?

Mythery
Автор

You can also use:
public RPGRandom() {

}

klopo
Автор

Hey benny, you should make a game similar to minecraft with more emphasis on redstone... PLZ!!! Make a tutorial on it!!!!

SkukS
Автор

the solution to your constructor problem"

public RPGRandom() {
this(new Random().nextInt());
}

tabularasa