[V, perhaps others] randint() and rand_int() not random at..

G

Guest

Guest
Archived from groups: rec.games.roguelike.angband (More info?)

For kicks, I used these two functions to choose a number between a range, and
from that number, it would display a certain message. This I coded in a
function for init2.c (sorta as a random greeting).

Imagine my surprise when I kept getting the SAME MESSAGE over and over!

So I did a simulation to see what the first 100 random numbers would spew out to
make sure it wasn't something stupid on my part. Sure enough, it would choose
the same 100 different numbers.

Am I doing something wrong? Then again, I don't know exactly how V handles its
RNG. It sure isnt randomized by time of day.

--
AKA Yumi_Saotome on #angband
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.angband (More info?)

Ernest Huang wrote:
> For kicks, I used these two functions to choose a number between a range, and
> from that number, it would display a certain message. This I coded in a
> function for init2.c (sorta as a random greeting).
>
> Imagine my surprise when I kept getting the SAME MESSAGE over and over!
>
> So I did a simulation to see what the first 100 random numbers would spew out to
> make sure it wasn't something stupid on my part. Sure enough, it would choose
> the same 100 different numbers.
>
> Am I doing something wrong? Then again, I don't know exactly how V handles its
> RNG. It sure isnt randomized by time of day.

Obviously, it's not seeding the rng from the system clock until after
the point in init2.c where you set this up. Move your code later in the
initialization.
--
http://www.gnu.org/philosophy/right-to-read.html
Palladium? Trusted Computing? DRM? Microsoft? Sauron.
"One ring to rule them all, one ring to find them
One ring to bring them all, and in the darkness bind them."
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.angband (More info?)

On 2005-04-11 01:15:50, Ernest Huang <animeband@oook.cz> wrote:

> For kicks, I used these two functions to choose a number between a range, and
> from that number, it would display a certain message. This I coded in a
> function for init2.c (sorta as a random greeting).
>
> Imagine my surprise when I kept getting the SAME MESSAGE over and over!
>
> So I did a simulation to see what the first 100 random numbers would spew out to
> make sure it wasn't something stupid on my part. Sure enough, it would choose
> the same 100 different numbers.
>
> Am I doing something wrong? Then again, I don't know exactly how V handles its
> RNG. It sure isnt randomized by time of day.
>
> --
> AKA Yumi_Saotome on #angband
>
>

Never mind, I am wrong ^_^; Disregard my idiot post.

So it does randomize after init but before the birth function.

--
AKA Yumi_Saotome on #angband