ID:153704
 
X, Y and Z. The variables for a turf that I'm using in combination to determine the seed for:

Psuedo-randomness, which uses a seed based on things such as x, y and z coordinates to determine that "random" value of something, and tends to have:

Patterns, the things which I want to avoid.

So, you've got a big 100x100 map of turfs. Each turf is given a psuedo-random value based on its x, y and z coordinates. ("x+y+z", "x*y*z", etc...) The value can be either 0 or 1. If its a 0, turn it black. If its a 1, turn it white.

Now observe, and you'll see a nice array of organized-looking "random" turf arrangements. So, the question is, how can I arrange the x, y and z values of each turf together to form a seed for the psuedo-random number generator without having visible patterns? Or can I?

As you can see from this example, the current results, well, suck.

O#OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O## #OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O# O#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O## #OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O# O#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O## #OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O# O#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O## #OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O# O#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O## #OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O# O#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O## #OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O# O#OO#OO#OO##O##O##O##O##O##O##O##O##O##O## #OO#OO#OO##O##O##O##O##O##O##O##O##O##O##O OO#OO#OO##O##O##O##O##O##O##O##O##O##O##OO
Foomer wrote:
X, Y and Z. The variables for a turf that I'm using in combination to determine the seed for:

Psuedo-randomness, which uses a seed based on things such as x, y and z coordinates to determine that "random" value of something, and tends to have:

Patterns, the things which I want to avoid.

So, you've got a big 100x100 map of turfs. Each turf is given a psuedo-random value based on its x, y and z coordinates. ("x+y+z", "x*y*z", etc...) The value can be either 0 or 1. If its a 0, turn it black. If its a 1, turn it white.

Now observe, and you'll see a nice array of organized-looking "random" turf arrangements. So, the question is, how can I arrange the x, y and z values of each turf together to form a seed for the psuedo-random number generator without having visible patterns? Or can I?

As you can see from this example, the current results, well, suck.

<code>O#OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O## > #OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O > OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O# > O#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O## > #OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O > OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O# > O#OO#OO#OO##O##O##O##O##O##O##O##O##O##O## > #OO#OO#OO##O##O##O##O##O##O##O##O##O##O##O > OO#OO#OO##O##O##O##O##O##O##O##O##O##O##OO</code>

Rofl sorry foomer but I have no idea what u just said. Sounds cool and all though hope u do what ever u are talking about.
In response to Green Lime
Its pretty simple, just do this:
mob/verb/Generate()
for(var/turf/T in world)
rand_seed(T.x*T.y*T.z)
T.text = pick("<font bgcolor=#000000> ", "<font bgcolor=#FFFFFF> ")
And watch as it "randomly" generates a nice map with paterns.

What I need is a way to arrange the x, y and z variables of each turf to form a number that won't create patterns like that, if there is a way to do that.
Try
z * (world.maxy + world.maxx) + y * (world.maxx) + x
In response to Theodis
It makes perfect zebra stripes. :o/

(Just realized I was spelling "pseudo" wrong, too.)
Foomer wrote:
X, Y and Z. The variables for a turf that I'm using in combination to determine the seed for:

Psuedo-randomness, which uses a seed based on things such as x, y and z coordinates to determine that "random" value of something, and tends to have:

Patterns, the things which I want to avoid.

So, you've got a big 100x100 map of turfs. Each turf is given a psuedo-random value based on its x, y and z coordinates. ("x+y+z", "x*y*z", etc...) The value can be either 0 or 1. If its a 0, turn it black. If its a 1, turn it white.

Now observe, and you'll see a nice array of organized-looking "random" turf arrangements. So, the question is, how can I arrange the x, y and z values of each turf together to form a seed for the psuedo-random number generator without having visible patterns? Or can I?

As you can see from this example, the current results, well, suck.

<code>O#OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O## > #OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O > OO#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O# > O#OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O## > #OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O > OO#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O# > O#OO#OO#OO#OO##O##O##O##O##O##O##O##O##O## > #OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O > OO#OO#OO#OO##O##O##O##O##O##O##O##O##O##O# > O#OO#OO#OO##O##O##O##O##O##O##O##O##O##O## > #OO#OO#OO##O##O##O##O##O##O##O##O##O##O##O > OO#OO#OO##O##O##O##O##O##O##O##O##O##O##OO</code>

If you just want to make it random, why not just do;
text = pick("O","#")


I may be misunderstanding. I would ask you to explain more clearly to me, but since this is my last day at home for a little over a week, I won't bother. ;)

~>Volte
In response to Foomer
Foomer wrote:
It makes perfect zebra stripes. :o/

(Just realized I was spelling "pseudo" wrong, too.)

That's the fault of the BYOND random number generator then since my formula should come up with a unique number for every tile :P.
In response to Volte
If I'm not mistaken, he wants the same map to be generated every time the same random number seed is used. However, he wants to do this while avoiding nasty patterns in the output.
In response to Volte
text = pick("O","#")

I may be misunderstanding. I would ask you to explain more clearly to me, but since this is my last day at home for a little over a week, I won't bother. ;)

~>Volte

Yeah he wants to set a random number seed so he can generate the same random map each time :).
In response to Theodis
The simplest solution for this then, would be to just use the rand() proc, but use the rand_seed() proc to seed it beforehand.

-AbyssDragon
In response to AbyssDragon
That's what he's doing.

The complication that makes this an issue is that, because this is actually intended to be used in a text-MUD for an infinite map, I can't pre-generate the map but I have to generate it based on the variables (x, y, z) present for each potential square on the map. Since no rooms would actually be present until something entered them, the x, y and z variables are the only things present before the room actually exists.

My current solution is this messy thing:

<code>proc/DetermineSeed(turf/loc) var/x = (loc.x+(loc.y*4.497)) *10 var/y = (loc.y+(loc.x/8.17)) *10 var/z = (loc.z) return round(x*y*z)</code>

I'm not sure what its doing, but it comes out with something that looks less patternized than usual, so I'm using it. :P However, the ideal solution would be to create map values that end up looking like something that would be generated using cellular automata.

(I'm hoping with values from 0 to 255, I can smooth out the map then convert it based on height to describe either water, beach, sparse forest or dense forest.)
In response to Foomer
Foomer, there is a slight problem with that one. Change the multipler *10 to *1000, simulating a larger x and y value, and you'll see the problem. It works up to a few thousand y and maybe somewhere around twice that many x, but then it breaks down.
In response to Foomer
Sorry o.o Ive been messing with your variable, changing and modifying it a bit here and there.. but I dont think what the impression I get of what you're trying to do is possible with something this simple.

My results differ from yours though, so I dont think its DMs fault. Maybe its windows or processor FPU based or something. ^^;

Also, no matter what map size you use, the pattern is exactly the same. A 10x10 map is always the lower left 10x10 tiles of a 100x100 map.

(I tried adding in a user given variable to the equation... it didnt help much, btu the patterns got pretty *_* *L*)

What I would probably do if I had the inclination, would be to use the max xyz of the map to shift things around a bit, so that a quasi-random tile is based off of the result of the tile in question. The math involved is beyond my current attention span though ^^;;

Just an idea
In response to Theodis
I tried:

<code>sqrt(z * (world.maxy + world.maxx) + y * (world.maxx) + x) mob/verb/Generate() var/list/list = list("<font bgcolor=#000000> ", "<font bgcolor=#FFFFFF> ") for(var/turf/T in world) var/seed = sqrt(T.z * (world.maxy + world.maxx) + T.y * (world.maxx) + T.x) T.text = random_pick(list, seed)</code>

And the results look a lot more random. Can anyone see any patterns in this?
In response to Foomer
<code>sqrt(z * (world.maxy + world.maxx) + y * (world.maxx) + x) </code>

Doh! :P

It was supposed to be world.maxy * world.maxx. That's probbaly what caused the pattern. Also to since BYOND starts at (1,1,1) rather than the standard (0,0,0) you probably want to shift the numbers by one so the end numbers are a bit smaller.

So it should be:
(z - 1) * (world.maxy * world.maxx) + (y - 1) * (world.maxx) + (x - 1)
In response to Theodis
It still looks like stripes.
I'm not quite sure what kind of randomness is to be expected when repeatedly seeding the random number generator. I'm rusty, but I think you are starting over every time you seed the generator. Your input is some pattern of x, y and z. Your output will have a pattern also. (Mind you, I have not tested this. However, isn't the point of the pseudo RNG to create numbers in the same order so you can use save/load methods like this?)

Perhaps you should try seeding the RNG with some function of z for each level and then take a randomly generated number for each turf on that level. Adding some function of x and y would probably be okay if you desired. The point is that the RNG has to exist with the same seed for multiple calls if you want to see random numbers.
My latest attempt is to merge the values generated by each square using several different random seeds. The resulting effect would be like overlaying a 10x10 square patterns on a 11x11 square pattern. At least, that's the goal. It may not be totally random, but at least it will provide more variety than the other versions would.

<code>mob/verb/Generate() for(var/turf/T in world) var/seed1 = T.x * T.y * T.z var/seed2 = sqrt(T.z * (world.maxy * world.maxx) + T.y * (world.maxx) + T.x) var/seed3 = T.x + T.y + T.z var/seed4 = (T.x * 1.175923) + (T.y * 1.622147) + (T.z * 0.9487) var/value = 0 rand_seed(seed1); value += rand(0, 64) rand_seed(seed2); value += rand(0, 64) rand_seed(seed3); value += rand(0, 64) rand_seed(seed4); value += rand(0, 64) if(value < 128) T.text = "X" else T.text = "_"</code>
In response to Foomer
Here's a cellular version of the above:

<code>mob/verb/GenerateCellular() for(var/turf/T in world) var/seed1 = T.x * T.y * T.z var/seed2 = sqrt(T.z * (world.maxy * world.maxx) + T.y * (world.maxx) + T.x) var/seed3 = T.x + T.y + T.z var/seed4 = (T.x * 1.175923) + (T.y * 1.622147) + (T.z * 0.9487) var/value = 0 rand_seed(seed1); value += rand(0, 25) rand_seed(seed2); value += rand(0, 25) rand_seed(seed3); value += rand(0, 25) rand_seed(seed4); value += rand(0, 25) switch(value) if(0 to 50) T.text = "." if(50 to 100) T.text = "@" for(var/turf/T in world) var/walls = 0 for(var/turf/N in orange(T, 1)) if(N.text == "@") walls++ if(walls < 3) T.text = "." else if(walls > 5) T.text = "@"</code>

[Edit]
I modified that code to overlay another layer on top of the other, the second layer using a different seed combination, so that there were a total of three terrain types (forest, plains and water). It also looks pretty darn random.

<code>.==...===.===##==....=..==..=.=..==..#=..===###==..===.==...==.. ===.....=.==.===..#...=#......==.#=.#=##=#==##=#=...#=.####==..= ======.=.===..##=####==#=.=#.===##======#=#=====##.#=#=#=#===#== #======#====.##==#=#====#=##=#======##=##=##=====#=#####=#====== #=.#=.=####=###==.##=====#=#=##====..===##==#====#=..#=.#.=..#== #.=....=#####.=#=...======..##=====.=####==##===##.=..=..##=..== .#=...=.==##..###===..====#=#####.=#=####=####====#==###.#=...#= =#==###==#=#===#=====.===###==#####=#=#==#=###==###=########.##. =====##==#####=#==....=====#=##===###==##.====##=##==##=.##=#==. ====#=.##==##=#=##=..=====#.=...=#=.#===.====.==#..==.#....====. =..##=#....==#=##=.=..===....===#.#==##...===.#==.=##..===.=.=.. ...##=##=.....#.==..=#==#.=#=.#=###=#==##===.####=###=###.....== =.==#==##=...#.=.#.==#===.##=#####==##==##===####==#=#=#=##..==. ===##=##==#==#==####==##===##=#===####=####==##==##.==##==#..=.. ..=###=####========.===.#.=.#==#==#..#.=####==#..==..=#==#..=..= .=#...==.=.======#..#.#=.######====...=..=#=.==.===..=#=.##...=. =.===#.===.=.#.=#..=.=#=#=====.##=#=#...##=#===.=====#=.=###.#=. ==#=.=#==...#.#=#==.#=####=====###========##===.#=====##.==#=#=# ###=##=##.=##=##====######=====##==========##===##====#.==###==# #==#===#.####=#=##==##=#==============..==..===...#.==.#=.===... .=#=.....=..#.=#...==#============.===..==..=...=#.=====........ .=#.=.=.=.....#=.=.#.##========#####==...=.=...#=.=..======.#=#. .#####......=#.#=.#==#========#####===#.#==...##=###=.....=##=#. ..==#====..##=#####===#======##=======#####.==##=##==..==####=#= ===#===#..====#=####=====#====#======###=##==##=#.===..===#####= ==##==##==...#.##=#=.===##======#.#===#.=.#...=#..=======#===... =##====..=..==.#####=.#=#=======....==...=.==...=.=.=====##====. .###.#==.=.#====####=###=.=..#=..##==....=#=#.=..=...===#==.=... #=#=##==..==#.===#==#=#=#=...#=###=#=..=####.=...=#==#=#=#=#..=. =######=#=.=##=#===##===######====##=====#=####=#######=#=#=##=. =#####=###=#=####=###===###=.=#==#=###===.####.###=####=#..##=.. ...=..==..#=..=.#.==#..=..==...==...=.#=..=.#.=...=.#.==.=....=. </code>
In response to Foomer
Quite random. Looks a lot more random than your other attempts :p