answersLogoWhite

0


Best Answer

Depends where is the data.

If you use a DB server, you can simply use the DB server's function (such as RAND()).

A simple MySQL query would be:

SELECT id, question FROM questions ORDER BY RAND() LIMIT 1,0;

You can also generate a random number using rand() and use:

SELECT id, question FROM questions WHERE id = '<random_numer_comes_here>' LIMIT 1,0;

But you'll have to ensure that that the id number exists (you can use a loop until you find one or reach max tries).

Hope that helps.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you generate random questions in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?&gt;


What is PHP and PHPMyAdmin?

PHP is a server-side scripting language that can be used to dynamically generate the content of web sites served up to a client. It can also be used for local shell scripting. PHPMyAdmin is a PHP based web interface for managing MySQL databases.


How would generate a random sample?

Each item in the population has an equal chance to be chosen. Usually a computer algorithm is used to generate a set of random numbers (most spreadsheet . Then the items are chosen using the set of random numbers, either as they come off the assembly line or if they are serialized, you can just go pick those items.


How do you generate random numbers in PHP?

Use the function "rand()" or "mt_rand()". Both functions will generate a random number (as a return value, so be sure to make it point to a variable - see examples). However, "rand()" is slower and uses a default PHP randomizing system. mt_rand() is four times as fast, and uses the Mersenne Twister randomizing format - which is much more random. Both functions have two optional parameters - a minimum integer and a maximum integer, respectively. By filling in these parameters, you will get a random number between the values you give (so, giving one and five will give you a random number that is no less than one, and no greater than five). These, again, are optional - and if left blank, the tiniest integer possible is no less than 0, and the largest integer possible is generated by the PHP function "getrandmax()" / "mt_getrandmax()" automatically. Examples, of which all are acceptable: ---- /* Examples using no parameters */ $randomNumber = rand(); $randomNumber = mt_rand(); /* Examples using parameters */ $randomNumber = rand(1, 5); $randomNumber = mt_rand(6, 10); ---- If your PHP build is version 4.2 or under, you will need to seed the random number generator with a value to base off of. "srand()" and "mt_srand()" (to be used with rand() and mt_rand() functions, respectively) can be used in this case. They both only have one optional parameter, which is any seed value - any number. If omitted, a random seed will be generated. More acceptable examples: ---- // Example using no parameters srand(); $randomNumber = rand(); // Example using the seed parameter srand(12345); $randomNumber = rand(); // Example using the "mt" random format functions (without parameters) mt_Rand(); $randomNumber = mt_rand(); // Example using the "mt" random format (with parameters) mt_rand(12345); $randomNumber = mt_rand(); ----


In maths do you answer random questions?

well if i didntwould i answer this?think about that love you :)

Related questions

What code is used to generate random questions from a database in visual basic?

You can use the Randomize() function in order for you to get random questions from your database. You can use the primary keys in the database for each question as the basis for the randomization process.


Which function is used to randomize number in Excel?

There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.There is a RAND function which can generate random numbers. The RANDBETWEEN function can generate numbers between a lower and upper limit.


Random Questions Are Good?

Random Questions are awesome! [;


Where can one find random questions online?

There is actually a website called Random Questions. There is an explanation of the importance of random questions and a list of 50 random questions. These questions are intended to be used for starting conversations.


What is a PHP parser?

PHP is a programming language, and parser specifically is part that reads human-readable representation of code to generate parse tree and later opcode representation of code that can be interpreted by php interpreter.


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?&gt;


How can random numbers be generated in Java?

Random numbers can be generated in Java using the "random" class. One needs a single "random" object to generate a series of random numbers as a unit.


How random are your questions?

Very.


What is that show where people get random funny questions and have to ask random people walking the streets the questions?

family feud


What is PHP and PHPMyAdmin?

PHP is a server-side scripting language that can be used to dynamically generate the content of web sites served up to a client. It can also be used for local shell scripting. PHPMyAdmin is a PHP based web interface for managing MySQL databases.


What is PHP used for?

PHP is a programming language that is used to generate dynamic web pages based on user requests and other data that changes such as store inventory, current news, or time of day.


Generate a php script that will display the grade on the basis of marks?

The following PHP function is an example of how you could achieve this: You would then call the function as follows: where *MARK* is the mark I hope this has helped, Cpl.Vadera