Example #1
0
void SoundFactory::setSoundSequence()
{
    // Seed the random number generator
    KRandomSequence randomSequence;
    randomList.clear();
    //get the number of sounds then shuffle it: each number will be taken once then the sequence will come back
    for (uint j = 0; j < sounds; j++) 
        randomList.append(j);

    randomSequence.randomize(randomList);
}
Example #2
0
QStringList WQQuiz::multiOptions(int i)
{
  QString *s;
  QStringList Result;
  WQListItem li = m_list[i];

  typedef QPtrList<QString> LS;
  LS *ls;
  ls = new QPtrList<QString>();

  int j;
  if (li.question() == 0)
  {
    j = 1;
  }
  else
  {
    j= 0;
  }

  s= new QString(m_table->text(li.oneOp(), j)); 
  if (Prefs::enableBlanks())
  {
    s->remove("[");
    s->remove("]");
  }
  ls->append(s);

  s = new QString(m_table->text(li.twoOp(), j));
  if (Prefs::enableBlanks())
  {
    s->remove("[");
    s->remove("]");
  }
  ls->append(s);

  s = new QString(m_table->text(li.threeOp(), j));
  if (Prefs::enableBlanks())
  {
    s->remove("[");
    s->remove("]");
  }
  ls->append(s);

  KRandomSequence rs;
  rs.randomize(ls);

  while (ls->count())
  {
    Result.append(*ls->first());
    ls->removeFirst();
  }
 return Result;
}
Example #3
0
void KWQQuizModel::activateBaseList()
{
    m_list.clear();
    m_errorList.clear();
    foreach(int l, m_quizList)
        m_list.append(l);

    if (m_quizMode > 2) {
        KRandomSequence rs;
        rs.randomize(m_list);
    };

    m_questionCount = m_list.count();
    m_currentQuestion = 0;
}
Example #4
0
void WQQuiz::listRandom()
{
  QPtrList<void> list;

  for(int i = 0; i < m_quizList.count(); i++)
    list.append((void*) i);

  KRandomSequence seq;
  seq.randomize(&list);

  QuizList items;
  for(int i = 0; i < m_quizList.count(); i++)
    items.append(m_quizList[(long) list.take()]);

  m_quizList.clear();

  for(int i = 0; i < items.count(); i++)
    m_quizList.append(items[i]);
}
Example #5
0
QStringList KWQQuizModel::multiOptions()
{
    QStringList ls;
    KRandomSequence rs;
    int a = -1;
    int b = -1;

    do
        a = rs.getLong(m_questionCount);
    while(a == m_currentQuestion);

    do
        b = rs.getLong(m_questionCount);
    while(b == m_currentQuestion || b == a);

    int row =  m_list.at(m_currentQuestion);
    int col  = column(row);
    if (col == 0)
        col = 0;
    else
        col = 1;
    ls.append(data(index(qAbs(row), col, QModelIndex()), Qt::DisplayRole).toString());
    row =  m_list.at(a);
    ls.append(data(index(qAbs(row), col, QModelIndex()), Qt::DisplayRole).toString());
    row =  m_list.at(b);
    ls.append(data(index(qAbs(row), col, QModelIndex()), Qt::DisplayRole).toString());

    if (Prefs::enableBlanks()) {
        for (int i = 0; i < ls.count(); i++) {
            ls[i].remove('[');
            ls[i].remove(']');
        }
    }

    rs.randomize(ls);

    return ls;
}
Example #6
0
int
main(int argc, char *argv[])
{
   KApplication a(argc, argv, "krandomsequencetest");

   long seed;
   KRandomSequence seq;

   seed = 2;
   seq.setSeed(seed);printf("Seed = %4ld :", seed);
   for(int i = 0; i < 20; i++)
      printf("%3ld ", seq.getLong(100));
   printf("\n");

   seed = 0;
   seq.setSeed(seed);printf("Seed = %4ld :", seed);
   for(int i = 0; i < 20; i++)
      printf("%3ld ", seq.getLong(100));
   printf("\n");

   seed = 0;
   seq.setSeed(seed);printf("Seed = %4ld :", seed);
   for(int i = 0; i < 20; i++)
      printf("%3ld ", seq.getLong(100));
   printf("\n");

   seed = 2;
   seq.setSeed(seed);printf("Seed = %4ld :", seed);
   for(int i = 0; i < 20; i++)
      printf("%3ld ", seq.getLong(100));

   seq.setSeed(kapp->random());

   QPtrList<QString> list;
   list.append(new QString("A"));
   list.append(new QString("B"));
   list.append(new QString("C"));
   list.append(new QString("D"));
   list.append(new QString("E"));
   list.append(new QString("F"));
   list.append(new QString("G"));

   for(QString *str = list.first(); str; str = list.next())
      printf("%s", str->latin1());
   printf("\n\n");

   seq.randomize(&list);

   for(QString *str = list.first(); str; str = list.next())
      printf("%s", str->latin1());
   printf("\n\n");

   seq.randomize(&list);

   for(QString *str = list.first(); str; str = list.next())
      printf("%s", str->latin1());
   printf("\n\n");

   seq.randomize(&list);

   for(QString *str = list.first(); str; str = list.next())
      printf("%s", str->latin1());
   printf("\n\n");

   printf("\n");
}