Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My system is Computerized Examination. But my problem is, how can i random all questions without repetition.?
Posted

Suppose you have table named "Question" in database.
Lets move now
create table #RandomQuestion  (id uniqueidentifier NOT NULL DEFAULT newid(),QuestionNo int)

insert into #RandomQuestion  (QuestionNo)
select QuestionNo from Question

select top 100 QuestionNo 
from #RandomQuestion 
order by id


Now you can use this 100/ 50/ etc. questions, as per your requirement, as your random ques.
 
Share this answer
 
Make an array of the questions/lookup-keys/indices/etc. for the questions and then shuffle the array.
Look at my solution in: playing cards game (make Random 4 groups of Numbers in Main Group)[^] for shuffling.
Present the questions in the shuffled order.
Don't re-use a question, once presented.
Shuffle again for the next sequence of questions.
 
Share this answer
 
Well this might be what you want
SQL
--Create sample table
create table Questions(
quid int,
questions nvarchar(100)
)
--Sampel Insert Query
insert into Questions values(1,'MY 1st Questions')
insert into Questions values(2,'MY 2nd Questions')
insert into Questions values(3,'MY 3rd Questions')
insert into Questions values(4,'MY 4th Questions')
insert into Questions values(5,'MY 5th Questions')
insert into Questions values(6,'MY 6th Questions')
insert into Questions values(7,'MY 7th Questions')
insert into Questions values(8,'MY 8th Questions')
insert into Questions values(9,'MY 9th Questions')
insert into Questions values(10,'MY 10th Questions')

and the solution is
SQL
with cte as(
select Abs(checksum(newid())%10) as ORdid ,* from questions
)
select top 5 * from cte order by ordid

see the Example[^]
 
Share this answer
 
My solution is you can create a Stored procedure and pass the Start and ending row no.In your vb.net application you can store the start and end row no to be populated from db.
For example i have created one table called question.

SQL
--Create sample table
create table Questions(
quid int,
questions nvarchar(100)
)
--Sampel Insert Query
insert into Questions values(1,'MY 1st Questions')
insert into Questions values(2,'MY 2nd Questions')
insert into Questions values(3,'MY 3rd Questions')
insert into Questions values(4,'MY 4th Questions')
insert into Questions values(5,'MY 5th Questions')
insert into Questions values(6,'MY 6th Questions')
insert into Questions values(7,'MY 7th Questions')
insert into Questions values(8,'MY 8th Questions')
insert into Questions values(9,'MY 9th Questions')
insert into Questions values(10,'MY 10th Questions')

here is sample query to display the selected rows count
SQL
Declare @startno int,@endno int
set @startno=0
set @endno=3
SELECT *
FROM (
     SELECT *, ROW_NUMBER() OVER (ORDER BY quid) AS rownos
     FROM Questions
     ) AS q
WHERE q.rownos BETWEEN @startno AND @endno

the output will be like this.

1	MY 1st Questions	1
2	MY 2nd Questions	2
3	MY 3rd Questions	3


The same query to display next 3 records
SQL
Declare @startno int,@endno int
set @startno=4
set @endno=6
SELECT *
FROM (
     SELECT *, ROW_NUMBER() OVER (ORDER BY quid) AS rownos
     FROM Questions
     ) AS q
WHERE q.rownos BETWEEN @startno AND @endno

the output will be like this.

4	MY 4th Questions	4
5	MY 5th Questions	5
6	MY 6th Questions	6


In your vb.net application in button clicks you can increment and decrement the start and end row nos.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 4-Dec-14 2:48am    
This looks more like an attempt at paging, but has nothing to do with OP's need to select random question until all questions have been at one point been selected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900