www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/08/21/20:18:30

Date: Mon, 21 Aug 1995 16:35:41 -0700
To: djgpp AT sun DOT soe DOT clarkson DOT edu
From: taps AT cyberstore DOT ca (Tapio Vocadlo)
Subject: LIB: Problems with rand()

I was trying the Fat DS program by J. Walker and modified it
to simply copy frame_buf (a 64,000 byte array) to video RAM.

I wanted some pixel noise on the screen so I added this:

  int i,x,y;
  unsigned char *adr;

  for(i=0; i<2000; i++) {
    y = rand()%200;
    x = rand()%320;
    adr = frame_buf + y*320 + x;  /* mode 13 pixel calc */
    *adr = rand()%256;

    /* ... and then frame_buf gets blitted to VRAM */
  }

What I got instead was randomly colored pixels spaced in a
very regular pattern, about six or eight pixels apart
on each scanline. Using srand() before rand() didn't
improve things much.

The random() function works fine, though. In Borland C,
rand() works just as well. Is djgpp rand() supposed to
be this way?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019