Hello everybody,
I have some numbers, for example 16, 20, 23, 40, 43
I need to generate a random number of only this numbers i have.
How could i make this on QT or C++ ??
Can somebody help me?
For the moment i have this:
Printable View
Hello everybody,
I have some numbers, for example 16, 20, 23, 40, 43
I need to generate a random number of only this numbers i have.
How could i make this on QT or C++ ??
Can somebody help me?
For the moment i have this:
This is smart enough :)
Code:
int fnc(){ static int nmbrs[] = {16, 20, 23, 40, 43}; int r = rand() % 5; // use something smarter than modulo here return nmbrs[r]; }
uau :D
Thank you very much, you can think digital very well :p
Hi everybody,
With following sql statement i am able to rand a id from my database..
Its works, but the number 1 come every 3. time i run it :(
Have somebody a idea how to solve this by this sql statement? :crying:
If it possible i would like to rand a id with sql..
Do you initialise the random number generator for your sql server with a pseudorandom seed? Moreover, as I said, modulo is not the best operator here... How many rows to you have in that table?
http://www.desilva.biz/mysql/random.html
http://forums.devarticles.com/mysql-...l-rows-16.html
http://www.tech-recipes.com/postgres...l_tips470.html
http://www.powerpostgresql.com/Random_Aggregate
Hi wysota,
I have on my sqlite database at the moment 250 rows, but the database will grow slowly..
My sended script works good, but just the number 1 repeat a lot..
The best solution for me would be that random numbers never repeats..
Have you a idea how to rand a number, and until my app is runing is not possible to rand a same number?
Thanks
What if you run the lottery 251 times?
You can create a table with numbers 1-250 sequenced randomly and then when you want a random number, take a random row, remove it from the table and return the result. But again, what will happen if you want to have 251 random numbers?Quote:
Have you a idea how to rand a number, and until my app is runing is not possible to rand a same number?
Hi wysota its a great idea..
If i would run 251 i will get 0 probally?
Hi Wysota, thats ok for my app..
Thank you, i will try it :)