Folks,
I'm trying to generate a random number between (0..10) less, say, 5.
new_index = rand(0..(old_index - 1)) || new_index = rand((old_index + 1)..10)
Can anyone shed any light?
Folks,
I'm trying to generate a random number between (0..10) less, say, 5.
new_index = rand(0..(old_index - 1)) || new_index = rand((old_index + 1)..10)
Can anyone shed any light?
new_sample_space = (0..10).to_a - [5] #=> [0, 1, 2, 3, 4, 6, 7, 8, 9, 10]
new_index = new_sample_space.sample #=> random integer from 0-10, except 5
Of course, doing this with a large range is probably not a good idea because of memory concerns. In such "huge" cases, you could possibly just get another random number after you get 5
.
loop do
new_index = rand(1..10)
break if new_index != 5
end