Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Red[
- author: {Nędza Darek}
- version: 0.0.2
- license: {
- - point to this gist/github
- - no warranties
- - use/modify everywhere
- }
- ]
- float-incr: function [v] [
- digits-after-dot: length? find/tail (to-string v) #"."
- s: copy "0."
- loop digits-after-dot - 1 [
- append s #"0"
- ]
- append s #"1"
- v + to-float s
- ]
- random-loot: function [chance [float!]][
- if chance > 1.0 [do make error! "chance bigger than 1.0"]
- digits-after-dot: (length? to-string chance) - 2 ; "0."
- chances: make block! N: 10 ** digits-after-dot
- chance-win: to-integer at (to-string chance) 3
- chance-fail: N - chance-win
- ; thank you @rebolek for reminding me about loop
- loop chance-fail[
- append chances 'fail
- ]
- loop chance-win[
- append chances 'win
- ]
- random chances
- random/only chances ; pick one
- ]
- state: 'fail
- chance: 0.001
- number-of-tries: 0
- while [state = 'fail][
- number-of-tries: number-of-tries + 1
- state: random-loot chance
- if 0 = mod number-of-tries 100 [ chance: float-incr chance]
- ]
- number-of-tries
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement