From: Grzegorz Wróbel on
Jerry Coffin wrote:
> 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.

Well, I checked it. If not initialized it behaves as if srand(1) was called.

I took a look once again and I know why Gernot got the black bitmap. His buggy code in the loop:
>for(int i=0; i<w*h; ++i){*pImageBits = RGB(rand(), rand(), rand());
has no sense.

The loop should be:
for(int i=0;i<w*h*3)
pImageBits[i] = BYTE(rand()%256);

or (worse, because will change the pointer):
for(int i=0;i<w*h*3)
*pImageBits++ = BYTE(rand()%256);



--
my website: http://www.4neurons.com/
my email: 677265676F727940346E6575726F6E732E636F6D
From: Jerry Coffin on
In article <eaee33$h61$1(a)nemesis.news.tpi.pl>,
/dev/null(a)localhost.localdomain says...
> Jerry Coffin wrote:
> > 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.
>
> Well, I checked it. If not initialized it behaves as if srand(1) was called.

Oops -- quite right. Sorry 'bout being off by one like that.

> I took a look once again and I know why Gernot got the black bitmap. His buggy code in the loop:
> >for(int i=0; i<w*h; ++i){*pImageBits = RGB(rand(), rand(), rand());
> has no sense.
>
> The loop should be:
> for(int i=0;i<w*h*3)
> pImageBits[i] = BYTE(rand()%256);
>
> or (worse, because will change the pointer):
> for(int i=0;i<w*h*3)
> *pImageBits++ = BYTE(rand()%256);

I hadn't looked at that part of the code, but you're certainly
correct -- he was repeatedly writing to the one pixel in the top,
left-hand corner, and never touching any other. From the looks of
things, the rest was being initialized to zeros, so the result was
black pixels...

--
Later,
Jerry.

The universe is a figment of its own imagination.
From: Grzegorz Wróbel on
Jerry Coffin wrote:

> I hadn't looked at that part of the code, but you're certainly
> correct -- he was repeatedly writing to the one pixel in the top,
> left-hand corner, and never touching any other. From the looks of

Most likely in bottom-left corner, unless his bitmap was top-down. So it was certainly hard to spot for him this one pixel was red. :)

--
my website: http://www.4neurons.com/
my email: 677265676F727940346E6575726F6E732E636F6D
From: Gernot Frisch on

"Grzegorz Wrbel" </dev/null(a)localhost.localdomain> schrieb im
Newsbeitrag news:eafnsf$jjq$1(a)atlantis.news.tpi.pl...
> Jerry Coffin wrote:
>
>> I hadn't looked at that part of the code, but you're certainly
>> correct -- he was repeatedly writing to the one pixel in the top,
>> left-hand corner, and never touching any other. From the looks of
>
> Most likely in bottom-left corner, unless his bitmap was top-down.
> So it was certainly hard to spot for him this one pixel was red. :)


Doh! Thank you. There was some other problem as well, but I got it
working now.


First  |  Prev  | 
Pages: 1 2 3
Prev: mystery thread
Next: eject cd?