|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
i'm creating an examination program, in which i have list of questions stored in a database. I want to randomize the questions so that they will become unordered for every different user of the examprog. At first I tried to randomize numbers first and for every random numbers will shown that will only be the time the computer will get the specific question number....errr...example (to make things clearer)....the computer starts to random say the first random number was 15 then the computer will look for question number 15 in the database then so on and so forth. But the problem is sometimes when u randomize numbers there will come a time that it'll show the same number, i want to avoid displaying the same question again so how can i do that (please don't tell me to use if conditions for i've already used it and if i have a 150 available questions it'll make the computer loads more longer)
|
|
#2
|
||||
|
||||
|
Load all the questions into an array initially and then use the random number generator to shuffle the array around a few times. One way to do this is (pseudo code):
1. For i = 0 to ubound(array) 2. Pick a random number x between 0 and ubound(array) 3. Interchange the contents of array[i] and array[x] 4. Next i Once you're done with that, you can then dump the shuffled questions out from the array, one at a time in sequence.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
Agree with Scorpions4ever!..
U can try regard cpu time as randomize seek,So everytime generate exclusive number.. |
|
#4
|
|||
|
|||
|
that's great scorpion4ever, though something pops up into my mind, is it possible to disarrange the records in a database?
|
|
#5
|
||||
|
||||
|
>> is it possible to disarrange the records in a database?
Yeah, but it's a heck of a lot easier (and probably faster) to do it in memory instead. |
|
#6
|
|||
|
|||
|
ok thnx hope i can ask you if i encountered another problem
|
|
#7
|
|||
|
|||
|
ok i've found some randomizing programs uses or creates text file and written in the text files are the numbers already shown so there will be iteration of numbers, can u please show me how to create this text file during run time and how can a program read from a text file?
|
|
#8
|
|||
|
|||
|
I am a Jr programmer . Scorpions4ever
,can you tell the solution to generate random question little more flexible. how i can generate randon numbers and store the values in array. if possible plese post the code samples pleeese... thanks |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > avoiding iteration of numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|