Calling random numbers from a set

T

tcb

I have a set of whole numbers (counting numbers) in tbl_WN. There is
a field [Is_Prime] that indicates whether the number is prime.

I would like to create a set of prime numbers, then randomly call any
number from that set. Based on what a user does on a form, a random
prime number may appear.

Can I create the set of prime numbers, have them stored in memory,
then call a random prime number from that set whenever I need one?

This code gives you an idea of how I am set up, loops through random
numbers in the set:

Dim intWN As Long

Dim db_Prime As Database
Dim rs_Prime As Recordset

Set db_Prime = CurrentDb
Set rs_Prime = db_Prime.OpenRecordset("Select WN from tbl_WN where
Is_Prime = -1 and WN between 1 and 10000")

rs_Prime.MoveFirst

Do Until rs_Prime.EOF

intWN = rs_Prime!wn

rs_Prime.MoveNext

Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top