Question: Way to obtain a "random" variable from a position

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 410 Views - Last Post: 09 May 2013 - 02:14 PM Rate Topic: -----

#1 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 12:18 PM

Im making a way of mining with a machine in my game, so I need to make a way of getting the material (ore) and the richness the place where the player placed the machine haves, I have an x and a y position, and I need to get a number "random" but that is allways the same for the position.

Also, I can implement a seed sistem to my game, so the seed can affect the resource.

I have tried by multipling a seed with the position, and rounding it, and I have made a table in a paper to help me thinking, but that didnt work.

Please help me finding a way to do it.

Is This A Good Question/Topic? 0
  • +

Replies To: Question: Way to obtain a "random" variable from a position

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 12:56 PM

Seed system time then generate your random number from that.
Was This Post Helpful? 0
  • +
  • -

#3 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:12 PM

View PostButchDean, on 09 May 2013 - 12:56 PM, said:

Seed system time then generate your random number from that.

But how to generate the richness (a number from 0 to 5) or the resource from the seed and the position?
maybe with the sin or the cos? but the problem with those is that the resource and the richness would be the same for each 360 tiles...

For example:
positions: x=1896, y=230
seed: 0.27391303889453
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9217
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:18 PM

What - are you trying to do something like minecraft? The algorithm that extrapolates that seed value into what ever you are trying to do - that's all on your shoulders.


http://www.minecraft...l_generation%29
http://minecraft.ign...ins-World-Seeds
Was This Post Helpful? 0
  • +
  • -

#5 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:24 PM

View Postmodi123_1, on 09 May 2013 - 01:18 PM, said:

What - are you trying to do something like minecraft? The algorithm that extrapolates that seed value into what ever you are trying to do - that's all on your shoulders.


http://www.minecraft...l_generation%29
http://minecraft.ign...ins-World-Seeds


I know how to generate the seed, thats easy, but the problem is the algorithm, what commands can I use to make it? D:
Was This Post Helpful? 0
  • +
  • -

#6 malerv  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 100
  • Joined: 01-July 09

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:24 PM

View Postficolas, on 09 May 2013 - 04:12 PM, said:

View PostButchDean, on 09 May 2013 - 12:56 PM, said:

Seed system time then generate your random number from that.

But how to generate the richness (a number from 0 to 5) or the resource from the seed and the position?
maybe with the sin or the cos? but the problem with those is that the resource and the richness would be the same for each 360 tiles...

For example:
positions: x=1896, y=230
seed: 0.27391303889453


Hi

Do you need the "richness" to be always the same for each game?
Why won't you compute the richness for each tiles at the start of the game and then store it?
If you can t I would look for a oscillating function (or any function with strong divergence) and do something like

i = x*1000+y // depend on the boundaries of x and y
richness = f(i) modulo richness_max
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9217
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:25 PM

The algorithm is up to you.. I have zero idea what you game is, what you need to generate, or any of the rules that _YOU_ the developer should have written down.
Was This Post Helpful? 0
  • +
  • -

#8 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:26 PM

View Postmalerv, on 09 May 2013 - 01:24 PM, said:

View Postficolas, on 09 May 2013 - 04:12 PM, said:

View PostButchDean, on 09 May 2013 - 12:56 PM, said:

Seed system time then generate your random number from that.

But how to generate the richness (a number from 0 to 5) or the resource from the seed and the position?
maybe with the sin or the cos? but the problem with those is that the resource and the richness would be the same for each 360 tiles...

For example:
positions: x=1896, y=230
seed: 0.27391303889453


Hi

Do you need the "richness" to be always the same for each game?
Why won't you compute the richness for each tiles at the start of the game and then store it?
If you can t I would look for a oscillating function (or any function with strong divergence) and do something like

i = x*1000+y // depend on the boundaries of x and y
richness = f(i) modulo richness_max


The problem, is that I dont want it to be a patern, and that makes it a patern that repeats each X tiles.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9217
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:27 PM

Procedural Content Generation:
http://pcg.wikidot.com/
Was This Post Helpful? 2
  • +
  • -

#10 malerv  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 100
  • Joined: 01-July 09

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:43 PM

modi123_1 post a nice link

But if you don't want pattern why don t you generate the richness like this :

for any tiles
tilesRichness = random() modulo richness_max

But as said modi123_1 we can t guess your needs, you should think about the rules your generation should follow.
Was This Post Helpful? 0
  • +
  • -

#11 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:48 PM

View Postmalerv, on 09 May 2013 - 01:43 PM, said:

modi123_1 post a nice link

But if you don't want pattern why don t you generate the richness like this :

for any tiles
tilesRichness = random() modulo richness_max

But as said modi123_1 we can t guess your needs, you should think about the rules your generation should follow.


I dont want any randomness, because to prevent lag, I dont want to save the richness and the resource and check if the machine is there, I want to remove the data when the machine is removed, and when it is placed again, in the same spot, store it in a variable, inside a table, so a loop can go throught the table checking all machines. : D: :

Im looking at the link modi posted, and everything is so complex in my opinion
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9217
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:50 PM

Quote

I dont want any randomness, because to prevent lag, I dont want to save the richness and the resource and check if the machine is there, I want to remove the data when the machine is removed, and when it is placed again, in the same spot, store it in a variable, inside a table, so a loop can go throught the table checking all machines. : D: :


I am not sure if it's a translation issue, but that made no sense.

Quote

Im looking at the link modi posted, and everything is so complex in my opinion

Well yeah.. it's a complex topic. Not everything has some sort of 'boiled down for the masses' write up.. somethings are just inherently complex and advanced.
Was This Post Helpful? 0
  • +
  • -

#13 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 01:57 PM

View Postmodi123_1, on 09 May 2013 - 01:50 PM, said:

Quote

I dont want any randomness, because to prevent lag, I dont want to save the richness and the resource and check if the machine is there, I want to remove the data when the machine is removed, and when it is placed again, in the same spot, store it in a variable, inside a table, so a loop can go throught the table checking all machines. : D: :


I am not sure if it's a translation issue, but that made no sense.

Quote

Im looking at the link modi posted, and everything is so complex in my opinion

Well yeah.. it's a complex topic. Not everything has some sort of 'boiled down for the masses' write up.. somethings are just inherently complex and advanced.


Sorry my mother tongue isnt english :S

What I want the code to do is this:

-The machine is placed, then, the code generates the richness and the resource from the position and stores it in a array.
-When the machine is destroyed, the array is removed, so the code doesnt need to check every tick to see if there is a machine in that spot.
-When the machine is placed in the same spot, the same richness and the same resource is generated, because it has been generated with an algorithm.

What I have atm, is:

-The code randomly generates the richness and the resource, and stores it in a variable
-Each tick, the code checks all the variables inside the a table, to see if there is a machine placed in each spot a machine has been placed in.
-When the player removes the machine, nothing changes, so each tick the code checks for all machines that have been placed, even if they have been removed.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9217
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 02:07 PM

What does "machine" mean? Is this some sort of in game object, or an actual pc on a network?


Quote

-The machine is placed, then, the code generates the richness and the resource from the position and stores it in a array.

Yeah.. that math is something you need to do. Read up on the procedurally generated content.. Define the variables, variances, etc.. and then sketch out some math algorithms.. sequences... etc. This is, literally, all up to you. There is no magic formula since each game is different.
Was This Post Helpful? 0
  • +
  • -

#15 ficolas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-May 13

Re: Question: Way to obtain a "random" variable from a position

Posted 09 May 2013 - 02:10 PM

View Postmodi123_1, on 09 May 2013 - 02:07 PM, said:

What does "machine" mean? Is this some sort of in game object, or an actual pc on a network?

The machine is a object in the game, a mining drill.
I have read some stuff in the link you sended, im going to try one of them.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2