Linear Congruential Generators

Share your advanced PureBasic knowledge/code with the community.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Linear Congruential Generators

Post by michaeled314 »

Code: Select all

;The period of a general Linear Congruential Generator
;is at most m, and for some choices of a much less than
;that. The Linear Congruential Generator will have a full
;period if and only if:

;1. c and m are relatively prime
;2. a-1 is divisible by all prime factors of m
;3. a-1 is a multiple of 4 if m is a multiple of 4

m.l = 88 ;the modulus
a.l = 45 ;the multiplier
c.l = 47 ;the increment
x.l = 22 ;the seed or start value

For i = 1 To m
 Debug x
 x = (a*x+c) % m
Next
The only thing I need to do now is make a program that generates a,c,x properly given a value for m
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

how would you go about generating coprime #'s to n
Post Reply