Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:20:35+00:00 2026-06-14T20:20:35+00:00

I am quite new in programming and aspiring to make a game using cocos2dx

  • 0

I am quite new in programming and aspiring to make a game using cocos2dx and sqlite. But I came across this problem where I can’t find an example on or how it can be done.

The first thing I want to do is to randomly select a row from a table which has been filtered by a range. For example there is a table with 100 rows. If I filter between the value 1 ~ 10 of Column D it resulted in 20 rows. From these 20 I want to randomly select one of them.

Secondly for that randomly selected row I want to collect 5 different value, but so far I was unable to find working example on how I can collect them.

Here is the code I try to come up with but is not working:

  • Query
int MinColumnD = 1;
int Max ColumnD = 10;
int Dice =  ( rand() % 19 ) + 1;
char sql_query[100];
sprintf(sql_query, "SELECT A, B, C, D, E FROM SQList WHERE (ColumnD BETWEEN %d AND %d) ORDER BY RANDOM() LIMIT 1", MinColumnD, MaxColumnD);
std::list<INFO> details;
sqlite3_exec(DB, sql_query, CallBack, &details, &errorMessage);

*Thanks to CL’s comment I updated the above query to include order by random() Limit 1. However when I run it and get to the section I get this error on xcode:

 Thread 1
 0 sqlite3_exec
 0x54cbd8: movl 60(%ebx), %eax   < Thread 1: EXC_BAD_ACCESS (code=1, address=0x444e418e)

This seems to only happen when I include the ‘ORDER BY RANDOM()’ as part of the query

  • Callback
int CallBack( void * pOutCount, int argc, char ** argv, char **azColName ){

std::list<Class::INFO> *pList = (std::list<Class::INFO >*)pOutCount;
Class::INFO items;
items._A = argv[0];
items._B = atoi(argv[1]);
items._C = atoi(argv[2]);
items._D = atoi(argv[3]);
items._E = atoi(argv[4]);
pList->push_back( items );
return 0;

}
  • Struct
struct Class::INFO {

std::string _A;
int _B;
int _C;
int _D;
int _E;

};

*Perhaps because the sqlite query is incomplete so I don’t get the result properly but I am not sure how exactly I am able to get the returned list of values from the std::list. Is it correct to think that after the query then I can just call the component inside the list to get the value like:

std::string A = details._A;
int B = details._B;
int C = details._C;
int D = details._D;
int E = details._E;

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:20:36+00:00Added an answer on June 14, 2026 at 8:20 pm

    You do not know which rowids end up in the filtered result, so you cannot use them.

    To get some random records from the filtered result, first order it randomly, then take the first record of that:

    SELECT A, B, C, D, E
    FROM SQList
    WHERE ColumnD BETWEEN ? AND ?
    ORDER BY RANDOM()
    LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is obvious, but I'm quite new to python programming, why won't
I've been programming OpenGL for some time now but I'm quite new to OpenGL
I am quite new to programming. This is in relation to python. So the
I'm quite new to that functional programming paradigm, but so far I like it.
I'm quite new to C# and programming in general. Basically my problem is that
I am quite new to programming, so I'm a little scared to post. But
I am quite new to programming and will really appreciate if anyone can help
I'm quite new to java programming, but I'll try to use the correct terms
I am quite new to programming, but now experimenting with a table view app.
I'm quite new to programming in Python . I want to make an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.