Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

878739 Posts in 32935 Topics- by 24343 Members - Latest Member: Good Enough Games

May 22, 2013, 02:06:06 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)random number generators
Pages: [1]
Print
Author Topic: random number generators  (Read 402 times)
nikki
Level 10
*****


View Profile Email
« on: April 20, 2012, 07:33:25 AM »

Hi there!

I'm trying to get random data for heightmaps
when i concatenate the x and y location like this : value = (x Shl 16)| (z & $0ffff)
if gives me unique seeds to feed my random functions.

problem is the generated numbers are patterned, you see stripes and bands.

i think it has to do with the relative sameness of the concatenated numbers.

this is some example output :
0,0: seed: 0 = 8
0,1: seed: 65536 = 18
0,2: seed: 131072 = 16
0,3: seed: 196608 = 14
1,0: seed: 1 = 0
1,1: seed: 65537 = 18
1,2: seed: 131073 = 16
1,3: seed: 196609 = 14
2,0: seed: 2 = 0
2,1: seed: 65538 = 18
2,2: seed: 131074 = 16
2,3: seed: 196610 = 14
3,0: seed: 3 = 0
3,1: seed: 65539 = 18
3,2: seed: 131075 = 16
3,3: seed: 196611 = 14

I found some material about xor shifting couldn't get it do anything, so i'm hoping someone out there knows some solution to this.

 
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #1 on: April 20, 2012, 07:41:45 AM »

Which language?
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
nikki
Level 10
*****


View Profile Email
« Reply #2 on: April 20, 2012, 07:44:13 AM »

i'm working in blitzmax atm.

all the bit shift techniques are here though  Gomez
Logged
Rusk
Level 0
**


View Profile
« Reply #3 on: April 20, 2012, 08:00:53 AM »

If the seeds are truly unique (and they should be), then maybe the RNG is bad. It shouldn't be too hard writing your own version of http://en.wikipedia.org/wiki/Mersenne_twister or something.
Logged
st33d
Guest
« Reply #4 on: April 20, 2012, 08:18:13 AM »

I'm currently using XorShift and getting great results personally.

https://github.com/st33d/red-rogue/blob/master/src/com/robotacid/util/XorRandom.as

I generate the seed using the Date object. It's been creating some very crazy dungeons for me.
Logged
rivon
Level 10
*****



View Profile
« Reply #5 on: April 20, 2012, 11:16:47 AM »

Do you seed the random function before generating every random number? You should only seed it in the beginning... It looks like a bad RNG nonetheless.
Logged
nikki
Level 10
*****


View Profile Email
« Reply #6 on: April 20, 2012, 11:23:37 AM »

yeah i seed it every time,

if i'd only seed it at the beginning and i would like to know the heightmap at location 31546,27550 i'd have to generate millions of random nrs before i get the correct one.

thats why i seed it with the locationvalue (plus another seed.)

the xorshift was easily implemnted, but gave the same patterned result.
the Mersenne twister was alot more difficult, luckily i found a good example somewhere.
this one did the trick !!! , only trouble now is the seeding (it takes +3 seconds to seed and generate 512x512 values), i think thats because at every seedRnd() it generates a very big array of random numbers. I think i can fix that...
Logged
Dacke
Level 10
*****


I have never been to Woodstock


View Profile
« Reply #7 on: April 20, 2012, 01:00:22 PM »

Do you seed the random function before generating every random number? You should only seed it in the beginning... It looks like a bad RNG nonetheless.

afaik as I know, many random number generators just use the last number as input:
Code:
number1 = RNG(first_seed)
number2 = RNG(number1)
number3 = RNG(number2)
...

If you use a good RNG that works like that, it shouldn't matter if you reinitialize it every time (when it comes to computational cost). But if your RNG is really crappy, you can of course get similar numbers from similar seeds.
« Last Edit: April 20, 2012, 01:31:17 PM by Dacke » Logged

vegan • socialist • atheist • humanist • liberal • FOSSer
programmer • feminist • animal rights activist • pacifist • teetotaller
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic