From: Grzegorz Wróbel on
Gernot Frisch wrote:
>>Did you initialize the generator?
>
>
> What does that mean?
>

Well before using any generator you have to call a function that initialize it. Otherwise you'll get zeros.
So in case of built-in C simple, linear congruency generator, you'll need to call srand() once before calls to rand().
srand(time(NULL));

I think you might have other bug in your loop, but once generator is working you'll discover it yourself.

--
677265676F727940346E6575726F6E732E636F6D
From: Alex Fedotov on
Gernot Frisch wrote:

>> The bitmap created by CreateDIBitmap has the same color depth as the
>> passed in device context. Since the device context obtained by GetDC
>> initially contains a 1x1 monochrome bitmap, your code ends up creating a
>> monochrome bitmap out of the RGB array.
>
> GetDC(NULL) is the desktop window's DC - isn't it?

You are probably right here, desktop window's DC should be good enough
to set the color format.

-- Alex Fedotov


From: Alex Fedotov on
Grzegorz Wrbel wrote:

> Well before using any generator you have to call a function that
> initialize it. Otherwise you'll get zeros.

I don't think so. What will happen is that the sequence will be the same for
every run, but it won't be all zeroes either.

-- Alex Fedotov


From: Grzegorz Wróbel on
Alex Fedotov wrote:
> Grzegorz Wrbel wrote:
>>Well before using any generator you have to call a function that
>>initialize it. Otherwise you'll get zeros.
>
>
> I don't think so. What will happen is that the sequence will be the same for
> every run, but it won't be all zeroes either.

It would be the same only if you initialized the generator with constant value.
I'm not sure how how it is with rand(), but many more advanced generators. if not initialized usually behave like that (they often have few internal parameters that need to be set to proper values). Although formaly you can only say their behaviour is undefined.

--
my website: http://www.4neurons.com/
my email: 677265676F727940346E6575726F6E732E636F6D
From: Jerry Coffin on
In article <eabdd9$lc0$1(a)nemesis.news.tpi.pl>,
/dev/null(a)localhost.localdomain says...

[ ... ]

> > I don't think so. What will happen is that the sequence will be the same for
> > every run, but it won't be all zeroes either.
>
> It would be the same only if you initialized the generator with constant value.
> I'm not sure how how it is with rand(), but many more advanced generators. if not initialized usually behave like that (they often have few internal parameters that need to be set to proper values). Although formaly you can only say their behaviour is undefined.

The C standard requires that if you don't call srand(), rand() will
act as if srand(0) had been called -- i.e. it's initialized, and
returns some pseudo-random stream, but the stream will be the same
every time the code is run.

--
Later,
Jerry.

The universe is a figment of its own imagination.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: mystery thread
Next: eject cd?