# Thread: random generators

1. ## random generators

Can you please give me the code a program that shuffles random sentences/phrases? Please help. Thanks.

2. Do you know about arrays?

Do you know that array subscripts are integers?

Do you know how to generate a random number from 0 to N-1 (N being the size of the array)?

If you know some of these things, then you're well on the way to being able to at least post your OWN attempt at solving the problem.

3. Originally Posted by Salem
Do you know about arrays?

Do you know that array subscripts are integers?

Do you know how to generate a random number from 0 to N-1 (N being the size of the array)?

If you know some of these things, then you're well on the way to being able to at least post your OWN attempt at solving the problem.
Im new at those things sir. Pls help me. My professor havent discuss anything about arrays. I want to learn it advance. Thanks

4. Please give more detailed terms of reference. I have a suspicion that you do not understand the strict meaning of the word "shuffle" and you actually need something else.

Ideally, write a program, you want to make it work properly. Even if it is blank with no real content.

For example:

Code:
```// program Fortune Teller

char* fortunes[500];

int main(void)
{
unsigned int i;
for( i = 0; i < 5; ++i ) {
do {
unsigned int f = rand() % 500;
} while( already_used(f) );
puts(fortunes[f]);
}
return 0;
}```
This pseudo-program tells 5 unique fortunes from 500.

5. I want to make a word game. I want each questions to be shuffled and displayed randomly. Is it possible sir? Thanks for the code anyway.

6. If you can dream it, you can do it. -- Tom Fitzgerald, a Disney Imagineer (frequently misattributed to Walt Disney).

7. I get the logic but i dont know the syntax. What's the command for shuffle? Please help me sir.

8. How about showing us a program you managed to write for yourself, so we can pitch the help at the right level.

9. I have a problem posting my code. My game comes in 3 modes. Easy, average and hard. I use switch statements for it to be able to select game modes. can i used the random number generator then use the if-else to print the question according to the number generated by the system?

10. Originally Posted by Moon River
can i used the random number generator then use the if-else to print the question according to the number generated by the system?
Sure. The purpose of an if/else construct is to allow things to be done based on whether particular conditions apply. There are alternatives as well.

11. Thanks sir. But for example in easy mode. Can i write the code under the case 1: or i have to do it outside the switch?

12. That's up to you. switch and if/else can be nested within each other if needed - with care.

Why don't you try it and find out? There are certainly limitations when nesting conditionals (if, switch, etc) but it is possible. If you get it wrong, your compiler will complain bitterly. That's its job, after all. So, if the compiler complains, don't panic - you will learn a fair bit from the exercise of interpreting compiler error messages to work out what problems it is complaining about, and fixing your code.

13. Thanks to all your answers sir. Im almost at it but i have a little problem. In generating random numbers, i sometimes get the same results consecutively. How can i make it generate numbers without repeating the same as before?

14. You can:
• Check to see if the newest number generated has already been generated, and if so, redo.
• Shuffle an array of possible numbers once, then pick the next number of this array to "generate" it.

15. How do you shuffle sir? What's the syntax for it?

Popular pages Recent additions