Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # referenced from http://rosettacode.org/wiki/Subtractive_generator
- # credits to Frizu (twitter: @KaidenFrizu) for fixing a roughly half-assed code I started without having enough sleep
- # imagine losing sleep over gacha drop rates... and you don't even play gacha
- # if being used, don't forget to input a seed to the function to reset rng sequence, else it will continue based from the prev. seed
- # the generation sequence is stored on temp55, pls don't alter or you'll lose sleep over it as well tnx
- subtractive_gen <- function(seed = NULL) {
- if(!is.null(seed)) {
- temp <- c()
- reorder_temp <- 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 <- tail(reorder_temp, n = 55)
- }
- temp55 <- append(temp55, (temp55[56-55] - temp55[56-24]) %% (10^9))
- temp55 <<- tail(temp55, n = 55)
- return(temp55[56])
- }
Add Comment
Please, Sign In to add comment