This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arkfunc.R
181 lines (146 loc) · 5.71 KB
/
arkfunc.R
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
srand <- function(seed = NULL) { #Derived from Rosetta Code website; made by SurfChu85
if(is.null(seed)) {
if(!exists("TEMP55")) srand(as.integer(Sys.time()) %% (10^9))
TEMP55 <- tail(TEMP55, n = 55)
TEMP55 <- append(TEMP55, (TEMP55[56-55] - TEMP55[56-24]) %% (10^9))
TEMP55 <<- TEMP55
return(TEMP55[56])
}
if((seed <= 10^9-1 & seed >= 1) == FALSE) stop("Seed must be between 1 and 10^9-1")
temp <- c()
reorder_temp <- c()
result <- c()
temp[1] <- seed
temp[2] <- 1
for(i in 3:55) temp[i] <- (temp[i-2] - temp[i-1]) %% (10^9)
for(i in 1:55) reorder_temp[i] <- temp[((34*(i)) %% 55)+1]
for(i in 56:220) (reorder_temp[i] <- (reorder_temp[i-55] - reorder_temp[i-24]) %% (10^9))
TEMP55 <<- append(reorder_temp, (reorder_temp[56-55] - reorder_temp[56-24]) %% (10^9))
return(invisible(NULL))
}
mtrng_sim <- function(reps, iteration
,master.seed = NULL
,seedtype = c("default","rng","time")) {
if(!is.null(master.seed)) set.seed(master.seed)
suppressWarnings(if(!(seedtype %in% c("default","rng","time")))
stop("Invalid seedtype"))
dist_matrix <- matrix(nrow = reps, ncol = iteration)
seedtype <- seedtype[1]
tallydata <- c()
seed_list <- c()
returnlist <- list()
for (j in 1:iteration) {
if(seedtype == "time") {
Sys.sleep(2*10^(-3))
seed <- (as.numeric(Sys.time()) * (10^9)) %% (10^9)
seed_list <- c(seed_list, seed)
set.seed(seed)
}
else if(seedtype == "rng") {
seed <- (runif(1)*10^9) %% (10^9)
seed_list <- c(seed_list, seed)
set.seed(seed)
}
for(i in 1:reps) {
attempt <- 0
result <- 1
rateformula <- 0.02
while(result > rateformula) {
attempt = attempt + 1
rateformula <- 0.02 * max(1, attempt-49)
result <- runif(1)
}
dist_matrix[i,j] <- attempt
}
}
returnlist[["results"]] <- dist_matrix
for(k in 1:99) tallydata <- c(tallydata, sum(dist_matrix == k))
tallydata <- data.frame(c(1:99), tallydata, cumsum(tallydata)
,(tallydata / sum(tallydata)), cumsum(tallydata / sum(tallydata))
,"mtrng", seedtype)
names(tallydata) <- c("pulls","freq","c.freq","prob","c.prob","rng","seedtype")
returnlist[["tally"]] <- tallydata
if(seedtype == "rng" | seedtype == "time") {
seed_list <- data.frame(c(1:length(seed_list)), seed_list)
names(seed_list) <- c("iteration","seed")
returnlist[["seed_list"]] <- seed_list
}
else if(!is.null(master.seed)) returnlist[["seed_list"]] <- master.seed
else returnlist[["seed_list"]] <- NULL
return(returnlist)
}
sprng_sim <- function(reps, iteration
,master.seed = NULL
,seedtype = c("default","rng","time")) {
if(!is.null(master.seed)) srand(master.seed)
suppressWarnings(if(!(seedtype %in% c("default","rng","time")))
stop("Invalid seedtype"))
dist_matrix <- matrix(nrow = reps, ncol = iteration)
seedtype <- seedtype[1]
seed_list <- c()
tallydata <- c()
returnlist <- list()
for (j in 1:iteration) {
if(seedtype == "time") {
Sys.sleep(10^(-3))
seed <- (as.numeric(Sys.time()) * (10^9)) %% (10^9-1)
seed_list <- c(seed_list, seed)
srand(seed)
}
else if(seedtype == "rng") {
seed <- srand()
seed_list <- c(seed_list, seed)
srand(seed)
}
for(i in 1:reps) {
attempt <- 0
result <- 1
rateformula <- 0.02
while(result > rateformula) {
attempt = attempt + 1
rateformula <- 0.02 * max(1, attempt-49)
result <- srand() / (10^9)
}
dist_matrix[i,j] <- attempt
}
}
returnlist[["results"]] <- dist_matrix
for(k in 1:99) tallydata <- c(tallydata, sum(dist_matrix == k))
tallydata <- data.frame(c(1:99), tallydata, cumsum(tallydata)
,(tallydata / sum(tallydata)), cumsum(tallydata / sum(tallydata))
,"sprng", seedtype)
names(tallydata) <- c("pulls","freq","c.freq","prob","c.prob","rng","seedtype")
returnlist[["tally"]] <- tallydata
if(seedtype == "rng" | seedtype == "time") {
seed_list <- data.frame(c(1:length(seed_list)), seed_list)
names(seed_list) <- c("iteration","seed")
returnlist[["seed_list"]] <- seed_list
}
else if(!is.null(master.seed)) returnlist[["seed_list"]] <- master.seed
else returnlist[["seed_list"]] <- NULL
return(returnlist)
}
arknights_dist <- function(n) {
if(n <= 0) stop("n must be positive")
n <- as.integer(n)
pulls <- as.numeric(1:99)
pr <- as.numeric(1)
prob <- rate <- as.numeric()
type <- as.character()
for(i in pulls) {
rateformula <- 0.02*max(1,i-49)
rate <- c(rate,rateformula)
prob <- c(prob, prod(pr)*rateformula)
if(length(prob) != 0) pr <- c(pr, 1-rateformula)
if(i <= 50) type <- c(type, "nonpity")
else type <- c(type, "pity")
}
freq <- round(n * prob)
c.prob <- cumsum(prob)
c.freq <- cumsum(freq)
odds <- prob / (1 - prob)
fail.odds <- (1 - prob) / prob
return(data.frame(pulls, type, rate
,freq, c.freq, prob, c.prob
,odds, fail.odds))
}