🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #2

random number generator

#2
From: lovens weche
Date: Sun, 01 Jun 2003 10:11
62 lines
3162 bytes
Hi, for a lotto program I'm working on I want to code a random number
generator *but*  numbers generated must be always different.

ex:

1st number genereated: 2
2nd number generated: 6
3rd number generated: 2 (WRONG!!! bad "period" as they say I think)

ok so we can forget the rand() funtion (please don't tell me to code a
routine that checks numbers generated and if they repeat re-draw a number,
bad performance code...)

ok here's the code I have to genereate the random numbers.. the variable a,
c and m must be set by me the programmer.. hummm thats where my problems
begin...

--- the code (don't you love the C programming language?
;) ------------------

a = 2 ^ 31;
c = 3;
m = (2 ^ 31) -1;

// wait 1 millisecond

VectCurrPtr[0] = (a * time() + c) % m;

for (i = 1; i < NumElem; i++)
    VectCurrPtr[i] = (a * VectCurrPtr[i - 1] + c) % m;

----------------------------------------------------------------------------
---------

so based on the tutorial I have this should generated random numbers all
stored in the VectCurrPtr array... the only problem is that so they don't
repeat you have to give the good values to a, c & m, thats my problem.

based on my tutorial I'm using here's the rules for setting a, c & m:

---
rules ----------------------------------------------------------------------
-------------

a- The only positive integer that exactly divides both m & c is 1 (c is
relatively prom to m)
b- if q is prime number that divides m ,then q divides a - 1
c- if 4 divides m, then 4 divides a - 1

----------------------------------------------------------------------------
-----------------

so if you eant look at the rules, then my code and tell me if my numbers
will repeat. AND DON'T TELL ME TO CODE ADDITIONAL CODE TO CHECK IF THEY
REAPEAT!!! already done that :(



Lovens / HyperGames Research & Development

ps: if you can send reply directly to my emial address that would be great:
mailto:lovcapone@hotmail.com
Technical Details
Message-ID: <SikCa.1506$Z83.788@wagner.videotron.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusenet.com!wesley.videotron.net!wagner.videotron.net.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1014db,da54b5a763359bc3,start
X-Google-Attributes: gid1014db,public
X-Google-Thread: 10d4ba,da54b5a763359bc3,start
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,da54b5a763359bc3,start
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 2003-06-01 03:11:11 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusenet.com!wesley.videotron.net!wagner.videotron.net.POSTED!not-for-mail
From: "lovens weche" <fw1803@videotron.ca>
Newsgroups: att.lang.c++,comp.lang.c,comp.lang.c++
Subject: random number generator
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <SikCa.1506$Z83.788@wagner.videotron.net>
Date: Sun, 1 Jun 2003 06:11:15 -0400
NNTP-Posting-Host: 66.131.83.25
X-Complaints-To: abuse@videotron.ca
X-Trace: wagner.videotron.net 1054462258 66.131.83.25 (Sun, 01 Jun 2003 06:10:58 EDT)
NNTP-Posting-Date: Sun, 01 Jun 2003 06:10:58 EDT