Remember
Register
All Activity
Tags
Users
Ask a Question
About Boostr
Advertise on boostr.in
Jobs
Organizational Research By
Surprising Reserch Topic
algorithm for generating a random number
algorithm for generating a random number Â using -'php,mysql,algorithm,random,pseudocode'
I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever way of solving the problem in an elegant solution in that the following criteria is met:
1) The least amount of queries to the database are made.
2) The least amount of crawling through a data structure in memory is made.
Essentially the idea is to do the following
1) Create a random number from 0 to 9999999
2) Check the database to see if the number exists
Â Â Â Â OR
2) Query the database for all numbers
3) See if the returned result matches whatever came from the db
4) If it matches, repeat step 1, if not, problem is solved. Â
Thanks.
Â Â Â Â
php
mysql
algorithm
random
pseudocode
asked
Sep 16, 2015
by
abhi
Please
log in
or
register
to add a comment.
0
votes
8
views
Related Hot Questions
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or
register
.
...