1

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 ;-)

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
jwillmer
  • 3,570
  • 5
  • 37
  • 73
  • 1
    If I understand this correctly, you want to have a higher probability for cards that the user has answered wrong? – Jakub Hampl Mar 16 '11 at 12:14
  • you´r right :-) was i to detailed? *sry* – jwillmer Mar 16 '11 at 12:16
  • You might then find my answer here interesting: http://stackoverflow.com/questions/5243688/choosing-individuals-from-a-population-by-a-fitness-function/5243844#5243844 I think your algorithm sounds more or less OK. – Jakub Hampl Mar 16 '11 at 12:22
  • 1
    Your algorithm seems to favour cards with larger number of correct answers because adding a large number is more likely to exceed your random integer than adding a small number. If you want to favour cards the user has answered incorrectly, you should use 100-integer value. – freespace Mar 16 '11 at 12:30
  • @freespace if the user answerd a question right i multiply the int-value with 0,x and round it, for wrong answers i use 1.x as multiplyer ;-) – jwillmer Mar 16 '11 at 12:40

2 Answers2

1

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.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

Found my answer on math.stackexchange.com : Algorithm for randomly choosing learning cards

Community
  • 1
  • 1
jwillmer
  • 3,570
  • 5
  • 37
  • 73