Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Srs halp thred guise

Name: Anonymous 2009-07-10 23:19

I wrote a quickie program that does a 2D random walk.  It works fine for a while, but after around 250,000 loops, it stops drawing.  WAT'S WRONG /PROG/?? D:

void DoStuff(HWND hwnd, HDC hdc) {
    WINDOWINFO wnd;
    int xmax, ymax, x, y, r;

    srand((unsigned int)time(0));
    GetWindowInfo(hwnd, &wnd);

    xmax = wnd.rcClient.right - wnd.rcClient.left - 1;
    ymax = wnd.rcClient.bottom - wnd.rcClient.top - 1;

    x = xmax / 2; y = ymax / 2;

    while (1) {
        SetPixel(hdc,x,y,0);

        if ((r = (rand() % 4)) >= 2)
            x = (x + (2*(r % 2)-1) + xmax) % xmax;
        else
            y = (y + (2*(r % 2)-1) + ymax) % ymax;
    }
}

Name: Anonymous 2009-07-11 0:52

runs out of willing iterations

Name: Anonymous 2009-07-11 1:17

It's a known problem with the “drunk walk” algorithm. Eventually it sobers up.

Name: Anonymous 2009-07-11 12:25

r % 2
:(

Name: Anonymous 2009-07-11 13:24

You should install Ubanto/Gentoo and write this in curses.

Name: Anonymous 2009-07-11 18:42

>>3
I loved your post. Don't really feel like finding that memetic display, so .. keep posting!

Name: Anonymous 2009-07-11 19:21

r % 2

This is why schools need to keep teaching assembly.

Name: Anonymous 2009-07-11 19:33

OP here, I figured it out myself you useless tards.  The random number generator was cyclic and after a little while, it came back to where it started and retraced the entire path all over again, making it look like it wasn't doing anything.  Solution: reseed random number generator every so often.

>>4

(int)fmod((double)r, 1.0)

Better?

Name: Anonymous 2009-07-11 19:41

>>8
Do you mean  (int)fmod((double)r, 2.0)?

Name: Anonymous 2009-07-11 19:48

>>9
Do you mean  (int)(r-2*floor((float)r/2.0))?

Name: Anonymous 2011-01-31 21:09

<-- check em dubz

Name: tray 2012-03-14 15:52

you better be

Don't change these.
Name: Email:
Entire Thread Thread List