android - Get unique random word from pool each day -


i've pool of words (around 200 now) want display randomly each day without repetition.

in shared preference store date of last displayed word , if date today same, display same word displayed last time, today day need random word pool , display it.

i've tried achieve via 2 methods:

method 1: using sqlite db

  • pre fill db in assets folder (db has table 2 columns, words , isused)
  • on oncreate(sqlitedatabase database) copy pre filled db /data
  • use sqlite random entry db , update isused couter true
  • shave word in shared preference if user opens app again in same day show word
  • if i've update words in db then(by 150):
    • create db in assets folder new words
    • onupgrade(sqlitedatabase db, int oldversion, int newversion) copy db /data
    • copy each words in original db row row keeping isused column intact

instead of using pre filled db can insert 200 words using sql statement in oncreate , later update other 150 sql statements in onupgrade.

method 2: using shared preferences

  • use save 200 words
  • create string random numbers upto 200 , save in shared preference
  • pop 1 random number each day , show word index. if same day don't pop show last word
  • if i've update words(by 150):
    • check how words number increased , generate increased numbers in random order , shuffle original random string array

so question feel none of algo enough. there better way achieve , if not should go method 1, method 1 without pre filled db or method 2?

why not load strings simple text file in assets during oncreate/onupgrade, shuffle them , insert database? when need know word show, calculate number of days application installation (n) , show n-th word.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -