Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flea_simulate <- function (samples, teleport=FALSE) {
- n.samples = length(samples)
- flea.position <- runif(1, 0, 100)
- flea.positions <- rep(0, n.samples)
- for (i in 1:n.samples) {
- flea.position <- flea.position + samples[i]
- if (flea.position < 0) {
- flea.position <- abs(flea.position)
- } else if (flea.position > 100) {
- if (teleport) {
- flea.position <- flea.position - 100
- } else {
- flea.position <- 200 - flea.position
- }
- }
- flea.positions[i] <- flea.position
- }
- return(flea.positions)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement