Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
Created July 5, 2018 11:34
Show Gist options
  • Save nedzadarek/4e28c6016d9fc5679f127f9ac6fb263e to your computer and use it in GitHub Desktop.
Save nedzadarek/4e28c6016d9fc5679f127f9ac6fb263e to your computer and use it in GitHub Desktop.
random set bit from bitset
b: make bitset! "ajfnxiermnpqpau"
; b: make bitset! "z"
solution1: [
; make bitset! #{0000000000000000000000004A3810}
bl: copy []
; []
repeat w (length? b) [
if b/:w [append bl w]
]
; bl
; [97 100 102 106 107 108 115]
random/only bl
]
i: 0
tries: #()
tries/10: 0
tries/25: 0
tries/50: 0
solution2: [
i: 0
while [not b/(bit: random length? b) ][
i: i + 1
bit
]
if i > 10 [tries/10: tries/10 + 1]
if i > 25 [tries/10: tries/25 + 1]
if i > 50 [tries/10: tries/50 + 1]
]
print ["Length of b: " length? b]
; probe is
probe profile/count [
[do solution1]
[do solution2]
] 1'000
print "Number of tries of solution 2: "
print ["more than 10 tries: " tries/10]
print ["more than 25 tries: " tries/25]
print ["more than 50 tries: " tries/50]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment