www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/07/09:32:40

Date: Wed, 7 Dec 94 00:17:15 -0500
From: dj AT stealth DOT ctron DOT com (DJ Delorie)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: better rand()

This source demonstrates a better rand() function, which is similar in
algorithm to the one I'm using in V2.  Let me know if anyone finds any
non-randomness in this one.

Note: this test shows how non-random V1's rand() is, if you just
comment out the rand() here and use the system one.

Enjoy!
DJ
---------------
#include <graphics.h>

int rand()
{
  static unsigned long long next=0;
  next = next * 1103515245L + 12345;
  next = (next<<15) ^ (next >> 27);
  return next;
}

main()
{
  int mx, my, w;
  GrSetMode(GR_biggest_graphics);
  mx = GrSizeX();
  my = GrSizeY();
  w = GrWhite();
  while (!kbhit())
    GrPlot(rand()%mx, rand()%my, w);
  getkey();
  GrSetMode(GR_default_text);
  return 0;
}


- Raw text -


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