library(gmp) 

rand_BSD <- function(n = 1) {
  a <- as.bigz(1103515245)
  c <- as.bigz(12345)
  m <- as.bigz(2^31)
  x <- rep(as.bigz(0), n)
  x[1] <- (a * as.bigz(seed) + c)%% m
  i <- 1
  while (i < n) {
    x[i+1] <- (a * x[i] + c)%% m
    i <- i + 1
  }
  as.integer(x)
}

seed <- 0
rand_BSD(10)



rand_MS <- function(n = 1) {
  a <- as.bigz(214013)
  c <- as.bigz(2531011)
  m <- as.bigz(2^31)
  x <- rep(as.bigz(0), n)
  x[1] <- (a * as.bigz(seed) + c)%% m
  i <- 1
  while (i < n) {
    x[i+1] <- (a * x[i] + c)%% m
    i <- i + 1
  }
  as.integer(x / 2^16)
}

seed <- 0
rand_MS(10)