#NAPLES
#QUESTION 1
#Part A
r<-rep(0,100)
r[1]=13
a=17
b=0
d=100
for(i in 1:100)
{
r[i+1]<-(a*r[i]+b)%%d
}
r
## [1] 13 21 57 69 73 41 97 49 33 61 37 29 93 81 77 9 53 1 17 89 13 21 57
## [24] 69 73 41 97 49 33 61 37 29 93 81 77 9 53 1 17 89 13 21 57 69 73 41
## [47] 97 49 33 61 37 29 93 81 77 9 53 1 17 89 13 21 57 69 73 41 97 49 33
## [70] 61 37 29 93 81 77 9 53 1 17 89 13 21 57 69 73 41 97 49 33 61 37 29
## [93] 93 81 77 9 53 1 17 89 13
hist(r,xlab= 'random number',main = "Histogram of R")

#QUESTION 1
#PART B
set.seed(0914)
r[1]<-sample(0:100, 1)
r[1]
## [1] 6
for(i in 1:100)
{
r[i+1]<-(a*r[i]+b)%%d
}
r
## [1] 6 2 34 78 26 42 14 38 46 82 94 98 66 22 74 58 86 62 54 18 6 2 34
## [24] 78 26 42 14 38 46 82 94 98 66 22 74 58 86 62 54 18 6 2 34 78 26 42
## [47] 14 38 46 82 94 98 66 22 74 58 86 62 54 18 6 2 34 78 26 42 14 38 46
## [70] 82 94 98 66 22 74 58 86 62 54 18 6 2 34 78 26 42 14 38 46 82 94 98
## [93] 66 22 74 58 86 62 54 18 6
hist(r, xlab= 'random number', main = "Histogram of R with seed")

#QUESTION 2
#Part A
#There is only 64 points on the graph and I believe this is because
#the period is 64, so there are 64 points.
r<-rep(0,100)
a=13
b=1
d=64
for(i in 1:100)
{
r[i+1]<-(a*r[i]+b)%%d
}
r
## [1] 0 1 14 55 12 29 58 51 24 57 38 47 36 21 18 43 48 49 62 39 60 13 42
## [24] 35 8 41 22 31 20 5 2 27 32 33 46 23 44 61 26 19 56 25 6 15 4 53
## [47] 50 11 16 17 30 7 28 45 10 3 40 9 54 63 52 37 34 59 0 1 14 55 12
## [70] 29 58 51 24 57 38 47 36 21 18 43 48 49 62 39 60 13 42 35 8 41 22 31
## [93] 20 5 2 27 32 33 46 23 44
plot(r[1:100],r[2:101],xlab="R [i]", ylab= "R [ i+1 ]", main= "R [ i ] against R [ i + 1 ]")

#QUESTION 2
#Part B
r<-rep(0,100)
a=13
b=0914
d=64
for(i in 1:100)
{
r[i+1]<-(a*r[i]+b)%%d
}
r
## [1] 0 18 60 30 24 10 20 22 48 2 44 14 8 58 4 6 32 50 28 62 56 42 52
## [24] 54 16 34 12 46 40 26 36 38 0 18 60 30 24 10 20 22 48 2 44 14 8 58
## [47] 4 6 32 50 28 62 56 42 52 54 16 34 12 46 40 26 36 38 0 18 60 30 24
## [70] 10 20 22 48 2 44 14 8 58 4 6 32 50 28 62 56 42 52 54 16 34 12 46
## [93] 40 26 36 38 0 18 60 30 24
plot(r[1:100],r[2:101],xlab="R [i]", ylab= "R [ i+1 ]", main= "R [ i ] against R [ i + 1 ] with shift")

#The period for the new graph is 32 since we had a shift.