You'll still get a 1-in-3 chance of getting a tree just by using rand().
There are obviously better random number generators around which you
could use, ones which will give a better "randomness". You could look on
here:-
http://random.mat.sbg.ac.at/
Also, depending on processor speed, you will be executing several
hundred instructions in a millisecond.
--------------
Allan
-----Original Message-----
From: beginnersroguelikedevelopment@yahoogroups.com
[mailto:beginnersroguelikedevelopment@yahoogroups.com] On Behalf Of
gamer_2k4
Sent: 04 October 2005 03:13
To: beginnersroguelikedevelopment@yahoogroups.com
Subject: [Beginners Roguelike Development] Re: need help with a RNG
I use the random number generator for map creation, so if I want a 1
in 3 chance that a tree will be generated on a tile (instead of just
grass) and I have a 40 x 160 map, that's 6400 calculations in less
than a second. Even getting the milliseconds past midnight isn't
fast enough for that.
--- In beginnersroguelikedevelopment@yahoogroups.com, "allan175uk"
<allan@s...> wrote:
> I think you'd be better off just call srand() occasionally (or just
> once when your code starts).
>
> I tend to just call "srand(time(NULL))" near my program entry point
> and leave it at that, it seems pretty random to me! ;-)
>
> The last line (the return) is all you need really for a ranged
> random number.
>
> Also, even though PCs are getting faster & faster, calling time()
> once and GetTickCount() twice for *every* random number seems a bit
> excessive, especially as GetTickCount() will probably be returning
> the same number since the calls are only a few instructions apart!
>
> -----------
> Allan
_____
YAHOO! GROUPS LINKS
* Visit your group "beginnersroguelikedevelopment
<http://groups.yahoo.com/group/beginnersroguelikedevelopment> " on the
web.
* To unsubscribe from this group, send an email to:
beginnersroguelikedevelopment-unsubscribe@yahoogroups.com
<mailto:beginnersroguelikedevelopment-unsubscribe@yahoogroups.com?subjec
t=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
_____
[Non-text portions of this message have been removed]