Algorithm for randomly choosing learning cards
I'm programming a learning software. It works with question-/answercards. Now I need an algorithm to randomly pick the cards addicted to a integer-value from 0 - 100 that indicates how often the user has answerd the question right.
My actual idea is to count all integer-values, creating a random integer between 0 and the counted integer-values and use this integer to go through my cards and count their integers until I reached the random integer. Then I reach 开发者_如何学运维the integer I choose this card :-)
But there must be a better solution ;-)
I think the straightforward scheme that you describe is not unreasonable for the problem at hand.
If at some point in the future you find that it's inadequate (e.g. too slow), then you can think about optimizing it.
One possible optimization avenue would be to have a binary tree with cards at leaf nodes and each intermediate node containing the sum of the "scores" of the cards underneath. In this structure going from the random integer to the card, and updating a card's score could both be done in logarithmic time.
Found my answer on math.stackexchange.com : Algorithm for randomly choosing learning cards
精彩评论