Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] weird Qrand behaviour
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] weird Qrand behaviour

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doubitchou
    wrote on last edited by
    #1

    hi,
    the use of recommanded qrand works nice when executed in PC or through the nokia simulator, but failed strangely to randomize when executed from the N8 itself.
    Clearly : A function return a randomized QList, whereas the same function return an ordered QList each time.

    I really don't see what is wrong here.

    @
    QList <int> Keys_Dialog::RandomKeys ()
    {
    QList <int> Keys_Set ;
    QList <int> RemainingList ;

    int MAX_KEYS_NB = 10                 ;           // define the max nr of keys to generate
    int RandomValue = 0,  nb_val         ;
    
    
    nb_val = Keys_Set.count()            ;
    for (int i=0; i < MAX_KEYS_NB; i ++)
    {
           RemainingList.append (i)      ;
    }
    
    while( RemainingList.count () > 0)
    {
      RandomValue = (int) (((long) qrand() * RemainingList.count())/ RAND_MAX)  ;
    
          Keys_Set.append (RemainingList.at(RandomValue))                           ;
          RemainingList.removeAt (RandomValue);
          nb_val = Keys_Set.count()       ;
    

    qDebug() << "Keys_Dialog::RandomKeys : " << Keys_Set ;
    }

    return Keys_Set                       ;
    

    }@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca.cossaro
      wrote on last edited by
      #2

      Hi,

      I've not tested, but I think this

      @RandomValue = (int) (((long) qrand() * RemainingList.count())/ RAND_MAX);@

      is always 0

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doubitchou
        wrote on last edited by
        #3

        Correct !

        This was due to a bad init of the random generator that is lower in the the mobile.

        thx a lot.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved