So I have to implement a SkipList with the best efficiency for add, find, and delete methods. the list is required to use a random.nextBoolean() to check the probability of promoting its level. What I don't understand is how random.nextBoolean() works?
while (rand.nextBoolean()==true)
//jump to promotion method
The code is supposed to take a 50% percent chance of promoting to an upper level each time rand.nextBoolean is called, meaning the second time would be 25% and etc.
Right now regardless of true or false, I am entering my promotion method. I even added a fail safe if nextBoolean == false break to my code at one point and it still entered the loop AND the if statement. Why am I doing this and how can I fix it using the required nextBoolean() call?
Aucun commentaire:
Enregistrer un commentaire