-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci.m
47 lines (35 loc) · 942 Bytes
/
fibonacci.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
%% Fibonacci Generator for Uniform Random Deviates
clear all
close all
% ----------------------------------
% STEP 1: Congruential Random Generator
% ----------------------------------
% This is required for the first X numbers, before moving on to the
% Fibonacci generator for the remaining
% Parameters
a = 1597 ;
b = 51749 ;
M = 2^30 ;
N0 = 25; % Seed number
lcgnum = 17; % Number of linear congruential unif rand deviants required
ndeviates = 10000; % Number of deviates required
A = zeros([1,ndeviates]) ;
A(1) = mod(a*N0+b,M) ;
for i = 1:lcgnum-1
A(i+1) = mod(a*A(i)+b , M) ;
end
U = A ./ M ;
% ----------------------------------
% STEP 2: Fibonacci Random Generator
% ----------------------------------
for i = lcgnum+1:ndeviates
U(i) = U(i-17) - U(i-5) ;
if U(i) < 0
U(i) = U(i) + 1 ;
end
end
X = U(1:ndeviates-1) ;
Y = U(2:ndeviates) ;
%Plot in the [U(i),U(i+1)] plane
figure(1)
plot(X,Y,'r.')