Skip to content

Instantly share code, notes, and snippets.

@frbl
Last active March 28, 2017 23:24
Show Gist options
  • Save frbl/c306dbab940fced651488767ab86dbd7 to your computer and use it in GitHub Desktop.
Save frbl/c306dbab940fced651488767ab86dbd7 to your computer and use it in GitHub Desktop.
Sample from uniform distribution given a list of intervals
data <- c(1,2,1,3,2,1,2,3)
intervals <- c(0.1, 0.3, 0.6,1)
runif(data, intervals[data], intervals[data+1])
# Test if the output is correct:
check <- all(unlist(lapply(1:length(data), function(i) {res[i] >= intervals[data[i]] & res[i] <= intervals[data[i] + 1]})))
expect_true(check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment