473,902 Members | 4,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random Question generator for MS Access

1 New Member
I am use the MS Access Form as frontend and ms-access Database as backend
I want to retrive 10 question randomly from database out of 100 question
simultenously in richtextbox. If i click on next button then second question display.
I am use the four radio button for option
and I click on finish button then show the result and how iam store the 10 question with user answer in database.
Nov 24 '12 #1
14 9421
mojyzzzz
4 New Member
hi mohammad how are u?

I give u the select query to retrieve the top 10 records of a table,
I think the remaining would be so easy for u to do,

good luck
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 10 table1.id, table1.title, Rnd(id) AS Expr1
  2. FROM table1
  3. ORDER BY Rnd(id) DESC;
Nov 24 '12 #2
zmbd
5,501 Recognized Expert Moderator Expert
MohammadShabbir


- Mojyzzzz's solution will not prevent duplicate questions so it is advisable to check for these or use the "DISTINCT" and "M" has made some assumptions about your table design so be aware of the fact that you may well have to modify the query. ( SQL Predicates )

- As this is a somewhat familiar question often asked for homework or class projects I would ask/require that you post your current code and DB design. Note: that does not mean attach pictures or files as this information can be typed into the post quite easily.
Please remember to format your code and SQL blocks by using the <CODE/> button in the toolbar.
Nov 25 '12 #3
NeoPa
32,584 Recognized Expert Moderator MVP
You should also bear in mind that the suggested SQL will randomise the data for you, but it will be a repeatable randomisation, such that you will get the same random ten records each time it's run.
Nov 25 '12 #4
zmbd
5,501 Recognized Expert Moderator Expert
Thank you NeoPa, my oversite on SQL. I usually use VBA and open a recordset for this type of operation when creating my quizes for work.
Nov 25 '12 #5
mojyzzzz
4 New Member
If you want to prevent duplication, the only way is to create a table which stores any question ID that is seen by the user,

or the simple but not flexible way is to add a field that works as a flag that represents whether the question is seen or not
Nov 25 '12 #6
zmbd
5,501 Recognized Expert Moderator Expert
mojyzzzz
I assure you that there are easier ways than either method you've cited to achieve a random record set without duplication.
In fact, one of the very first threads I was involved with at this site dealt with the question of random record selection using weighted probabilities ( https://bytes.com/showthread.php?t=940752 ) which ran into just such a discussion.

If there is one thing I have learned over the years is to NEVER say that the "only" way to do some given task is to do it this way or that way.
Nov 25 '12 #7
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
NeoPa
You should also bear in mind that the suggested SQL will randomise the data for you, but it will be a repeatable randomisation, such that you will get the same random ten records each time it's run.
I would venture that its a bit more complicated then that. The seed number only returns the same result if the seed number is negative,
Example
Expand|Select|Wrap|Line Numbers
  1. Rnd(-1)=rnd(-1)
  2. rnd(1)<>rnd(1)
OR the seed has been reset just prior to running the random number generator each time.
Nov 25 '12 #8
Rabbit
12,516 Recognized Expert Moderator MVP
It should also be noted that Rnd(1) in a select query will return the same number for every row. That is because the function is run only once because the SQL engine assumes a function call with a static parameters will always return the same result.

The only way to get different numbers for each row is to vary the input by incorporating a field value.
Nov 25 '12 #9
NeoPa
32,584 Recognized Expert Moderator MVP
@Smiley & Rabbit
Well done lads. Both very good points. My post was in error and I overlooked the issue that Rabbit brought up related to SQL optimisations whereby it will determine that the function needn't be re-called as the parameters are the same. It essentially treats it as a constant value once called the first time.
Nov 26 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2405
by: Trythat | last post by:
This might seem a stupid question but here goes - I wrote a key generator for one of my programs in Visual Basic, so I recieve sales notification via email and then use my program to generate the key and send it via Email. Well after finding out about PHP, and that my host does PHP, I thought it would be quicker and more reliable to generate the keys on the server and send them out again either vai email or from the sales site.
21
3046
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to generate a set of random number that follow a normal distribution N(0,1) ? I am develloping on power4 machine running AIX. Thank you for your help
16
7198
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain unchanged). How can I do that in Python? Claudio Grondi
14
3514
by: kittikun | last post by:
Hi all, I was wondering if there is a random generator that is "reversible". I need to go back in time in my application and still need to use deterministic random numbers. Most of RNG implement the Next function but what about a Prev ? I know I can use an array to store X last values but I'm more interested to know if it exist something that allows to go backwards. Also I can't really afford to use the same seed and loop until i get
3
2985
by: adonis | last post by:
hello. i need some help with a c or c++ program. a program for generating random numbers with exponential and poisson distribution. please sombody help. thanks.
11
3029
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays of values. I get a random index value for each array so I can pull the data from them.
4
9408
by: Ruhi22 | last post by:
I am trying to use the default random generator in C. the funcion rand() is fine but when tried 'srand(time(0))' it is giving me the following error: error C3861: 'time': identifier not found the code I am tryin it in is as follows:
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.