Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

seeding randomly but can still do the same every time


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 the dodger uk   Members   -  Reputation: 148

Like
0Likes
Like

Posted 01 March 2013 - 07:26 PM

i need to place  objects in a scene via a height map , 

height maps are simple rows and collums.

the problem is if i place objects via this then it will be in colloms and rows and it can be seen , so it will look rubbish 

is there a way to do it so it looks random and better placed  but i will still get the same results every time i run the program

?



Ad:

#2 Vincent_M   Members   -  Reputation: 309

Like
1Likes
Like

Posted 01 March 2013 - 08:13 PM

So, are you just looking to generate new random numbers every different time? What language and what OS are you using?

 

In C, rand() will give you the same results every time based off of how long it takes to initialize the OS (I think), and even that can be OS-dependent (this is coming from a Linux background). You should be able to, however, change those results by seeding.

 

Check out srand(), if you're using C/C++. You can feed it time(NULL), which will gives the elapsed time in seconds since Jan 1st, 1970. In other words, the value changes just about every single time you call time(...), and feed the returned result to srand(), which then generates a new sequence of random values that can be retrieved by calling rand().

 

Here's a link: http://www.cplusplus.com/reference/cstdlib/srand/

 

What I did was call this in my game's initialization code:

srand(time(NULL));

 

 

Just call rand() like your normally do, and things should look differently from there. If you start seeing similar results, try calling that line in a few other places, but don't overuse it --it can be a heavy system call.



#3 Dragonsoulj   Crossbones+   -  Reputation: 1010

Like
0Likes
Like

Posted 01 March 2013 - 08:19 PM

If you want a random terrain, but be able to reload that same terrain, then base your generation off of rand() (if you are using C/C++), and seed the first load with the time, as Vincent_M stated above. Save the value of the seed and just load that same seed number to regenerate the same terrain.



#4 Khaiy   Members   -  Reputation: 821

Like
0Likes
Like

Posted 01 March 2013 - 08:38 PM

-EDIT-

 

Misread post



#5 BMacZero   Members   -  Reputation: 111

Like
0Likes
Like

Posted 02 March 2013 - 03:38 AM

You want random positions on a tile-based map, but you don't want the positions to be locked to the tiles, right?  The best way to do that is to generate numbers on a larger scale than your grid-based map is on.  For example, if your map is a 20x20 grid, generate random numbers from, say, 0-400 for the coordinates, then divide them by 20.  This will get you random decimal coordinates between 0-20.

 

And if you want the same results every time you run the program, you do not want to call srand, or you want to call it with constant number as a parameter.



#6 the dodger uk   Members   -  Reputation: 148

Like
0Likes
Like

Posted 02 March 2013 - 09:42 AM

cheers for the input , im not sure about the methods that are mentioned , but i think i have another way around it 

 

use the hightmap , and then use those cords on another height map  which uses the grid thing above and down  scales it by the 20 or so 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS