Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Red[
  2. author: {Nędza Darek}
  3. version: 0.0.2
  4. license: {
  5. - point to this gist/github
  6. - no warranties
  7. - use/modify everywhere
  8. }
  9. ]
  10. float-incr: function [v] [
  11. digits-after-dot: length? find/tail (to-string v) #"."
  12.  
  13. s: copy "0."
  14. loop digits-after-dot - 1 [
  15. append s #"0"
  16. ]
  17. append s #"1"
  18.  
  19. v + to-float s
  20. ]
  21. random-loot: function [chance [float!]][
  22. if chance > 1.0 [do make error! "chance bigger than 1.0"]
  23.  
  24. digits-after-dot: (length? to-string chance) - 2 ; "0."
  25. chances: make block! N: 10 ** digits-after-dot
  26.  
  27. chance-win: to-integer at (to-string chance) 3
  28. chance-fail: N - chance-win
  29. ; thank you @rebolek for reminding me about loop
  30. loop chance-fail[
  31. append chances 'fail
  32. ]
  33. loop chance-win[
  34. append chances 'win
  35. ]
  36.  
  37. random chances
  38. random/only chances ; pick one
  39. ]
  40.  
  41. state: 'fail
  42. chance: 0.001
  43. number-of-tries: 0
  44. while [state = 'fail][
  45. number-of-tries: number-of-tries + 1
  46. state: random-loot chance
  47.  
  48. if 0 = mod number-of-tries 100 [ chance: float-incr chance]
  49. ]
  50. number-of-tries
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement