Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 30 31 [32] 33 34 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100803 times)

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #465 on: February 07, 2012, 05:41:21 am »

While on the subject of RNG's (well, slightly), does anyone know of a decent pseudo-RNG that doesn't work with reseeding itself, and the seeding itself is really fast?

So effectively I want this:
Code: [Select]
int randomNumber = RandomGenerator(double x); and preferably I can do even this:
Code: [Select]
int randomNumber = RandomGenerator(double x, double y, double z, double u, double v);(Because yes, I need a 5 dimensional Perlin noise.)
The problem with the Mersenne twister etc. is that the numbers are called in order, and I won't know if the xth number I call is going to be the x+nth time the next time around, and I want a consistent (determined) result. And reseeding them every single time is quite an expensive call.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #466 on: February 07, 2012, 05:43:53 am »

The problem there is that you need to seed from something. Either the time, user input, or self seeding are the only options within my current understanding.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #467 on: February 07, 2012, 05:48:11 am »

The "double" input(s) is/are the seed.
I'm going to go with pre-calculated arrays of random numbers, that's definitely the fastest, I just hope the "periodicity" is large enough.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #468 on: February 07, 2012, 06:05:57 am »

Keep an eye on whether you want lower<=X<=higher or lower<=X<higher, and what the local rnd() function gives.  (Other combinations possible, but those two are the most common.)


If you can't work out how your system works, do a test on how many numbers pop out for a significant run.  Say 100 random numbers chosen from 1..10 (inclusive) and make sure you had roughly 10 of each, and no zeros (or less) or elevens (or more).  1000 times for 100 each would be better, etc, but it should highlight any under/overruns in either direction.

Then to test your negative range try testing -10..+10 (21 possible results, or -5..+15 if you want to test its asymmetry) across 1000 iterations.  You'd be looking at 47 or 48 results for each, but may vary a few in either direction.

Or even more times, if you're happy to wait the time needed for bigger numbers to be processed.  Or even a "continue forever, while uninterrupted" loop that updates its output accordingly that you can let run while you're not otherwise occupied, leaving it alone or staring at its potentially hypnotic results.  I've done that, before.  Although for different reasons... ;)


Anyway, in this deterministic universe of ours, I may have a thinko/typo in the above attempt at an explanation.  I'm sure someone else will be along in a moment to correct me or go "Huh?" about something. ;)
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #469 on: February 07, 2012, 06:08:28 am »

Code: [Select]
int randomNumber = RandomGenerator(double x, double y, double z, double u, double v);(Because yes, I need a 5 dimensional Perlin noise.)
The problem with the Mersenne twister etc. is that the numbers are called in order, and I won't know if the xth number I call is going to be the x+nth time the next time around, and I want a consistent (determined) result. And reseeding them every single time is quite an expensive call.

I'm not sure I understand what your asking for here. A mersenne twister, once initially seeded, will produce the same sequence of numbers. You don't need to reseed between each request. (this is true of most pseudo random generators)
« Last Edit: February 07, 2012, 06:10:16 am by Shades »
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #470 on: February 07, 2012, 06:15:08 am »

That is the problem, he doesn't want it to produce the same set.
Although I have no idea why that would be significant. What with the sheer number of seeds you could start from, it might as well be truly random. It isn't like anybody is going to sit down and find the logical process behind producing 5d noise for god sake.

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #471 on: February 07, 2012, 06:19:17 am »

That is the problem, he doesn't want it to produce the same set.
Although I have no idea why that would be significant. What with the sheer number of seeds you could start from, it might as well be truly random. It isn't like anybody is going to sit down and find the logical process behind producing 5d noise for god sake.

I want a consistent (determined) result

He wants a consistent result though, you can't have that and have a different set with the same starting seed. (although why you'd use the same starting seed then I don't know)
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #472 on: February 07, 2012, 06:22:45 am »

Found it: What I need is called a noise function.

@Shades: I'm going to be asking for values at locations, so "give a random value for x=1, y=2.00056, z=0.1111039", and I'll be doing that a few trillion times.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #473 on: February 07, 2012, 06:25:55 am »

So effectively I want this:
Code: [Select]
int randomNumber = RandomGenerator(double x); and preferably I can do even this:
Code: [Select]
int randomNumber = RandomGenerator(double x, double y, double z, double u, double v);(Because yes, I need a 5 dimensional Perlin noise.)

Right, if I understand correctly (which I might not), how about:

Use standard PRNG mechanism to get a seed number for each 'dimension' and (as I sort of mentioned in the previous message) for which you maintain separate PRNG streams.  That way, each stream is identical in each instance, regardless of which other (or how many other) streams have been tapped.  You can add a sixth call for a sixth dimension's seed and start that stream up without affecting the previous five streams-worth of randomness, and without having to generate a sixth column to a table.

And if you want a random-access randomness stream, the streams could each be a variant of "randomnumber(streamseed,Nthposition" where it calls the first random number from a stream based upon the seed "streamseed+Nthposition", and you can then forget about any further numbers in that stream.  Perhaps worse w.r.t. entropy (I'd be tempted to do something more complex, maybe hash the two values in some way) but, with a decent algorithm behind it, even that simple method won't be easily separated from noise, and yet gives you the same numbers for 1st, 2nd and 3rd position, even if you ask for them in order of 3rd, 2nd and 1st, and interspaced by alternate stream calls.

To that end, maybe your call could be "randomnumber(streamnumber,positionnumber)" and boil down to "seed with(fn(streamnumber,positionnumber)); return firstrandomnumber".  It would save the table, although you might want to statistically analyse an initial run to check there's no obvious problems.  The periodicity should probably be the same as your integrated randomness function, i.e. huge, but that's not guaranteed.


In light of those last two (three) ninjas... Huh?  I thought he did want identical/reproducible sets, just didn't know which separate dimensions would be requested each time, so couldn't be a single reproducible stream.  If not that, then ignore the above.  Probably best in the first place, actually.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #474 on: February 07, 2012, 06:29:26 am »

Found it: What I need is called a noise function.

@Shades: I'm going to be asking for values at locations, so "give a random value for x=1, y=2.00056, z=0.1111039", and I'll be doing that a few trillion times.
Do tell though... What do you need 5d for? And trillions? Is that hyperbole or is this a result of having that many dimensions to have to transverse?

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #475 on: February 07, 2012, 06:44:27 am »

Well, across five dimensions and 250 points on a 'side' you'd have just less than one 'short' trillion points in total.

4000 points on a side would give 1.024 trillion points in the classic/'long' measure, but much as I prefer that scale I don't think we're talking that one anyway.


Anyway, if you're going "I want a specifically reproducible 'randomness' for point[v, w, x, y, z]", I'm actually now thinking I'd be tempted just to hash the string "v,w,x,y,z" and use that result.  A basic hash (or hash-like formula, involving powers and mods) should do, to make it non-intensive per digit.  And less resource consuming than any table that would not give obvious periodicity (unless you can use a suitably large prime*prime*prime length of table such that it doesn't match any of the prime factors inherent in the array-size, and even then I'd want a few more unique primes to be sure).


But if you've already got a method, wahay!
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #476 on: February 07, 2012, 06:46:04 am »

Found it: What I need is called a noise function.

@Shades: I'm going to be asking for values at locations, so "give a random value for x=1, y=2.00056, z=0.1111039", and I'll be doing that a few trillion times.
Do tell though... What do you need 5d for? And trillions? Is that hyperbole or is this a result of having that many dimensions to have to transverse?
Whatever it is, I hope it's awesome.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #477 on: February 07, 2012, 06:50:38 am »

Anyway, if you're going "I want a specifically reproducible 'randomness' for point[v, w, x, y, z]", I'm actually now thinking I'd be tempted just to hash the string "v,w,x,y,z" and use that result.  A basic hash (or hash-like formula, involving powers and mods) should do, to make it non-intensive per digit.  And less resource consuming than any table that would not give obvious periodicity (unless you can use a suitably large prime*prime*prime length of table such that it doesn't match any of the prime factors inherent in the array-size, and even then I'd want a few more unique primes to be sure).
That sounds sort of bulky. Assuming you were genning longs, it would be a lot easier to use a standard 5d array. Hashing is fun, but totally not needed in this case when you can fish it out with a simple index.

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #478 on: February 07, 2012, 06:58:21 am »

Anyway, if you're going "I want a specifically reproducible 'randomness' for point[v, w, x, y, z]", I'm actually now thinking I'd be tempted just to hash the string "v,w,x,y,z" and use that result.  A basic hash (or hash-like formula, involving powers and mods) should do, to make it non-intensive per digit.  And less resource consuming than any table that would not give obvious periodicity (unless you can use a suitably large prime*prime*prime length of table such that it doesn't match any of the prime factors inherent in the array-size, and even then I'd want a few more unique primes to be sure).
That sounds sort of bulky. Assuming you were genning longs, it would be a lot easier to use a standard 5d array. Hashing is fun, but totally not needed in this case when you can fish it out with a simple index.

He mentioned noise functions which is exactly what you want for this kind of problem. Simplex noise is cheap for 5 dimensions and would let you pick any point in the 'grid'. Generating arrays or hashing is just over complicating it.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #479 on: February 07, 2012, 07:00:48 am »

But accessing this data would be fastest if you used your noise function to fill out an array first, unless you need to dynamically get new values.
Pages: 1 ... 30 31 [32] 33 34 ... 91