Flash Games

 FAQ   Search   Members   Groups   User Control Panel      Login 

It is currently Tue Dec 02, 2008 11:16 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Randomizing numbers without repeating
PostPosted: Sat Aug 30, 2008 7:48 am 
Offline

Joined: Sat Aug 30, 2008 7:13 am
Posts: 3
Hi, I'm an extreme noob to coding, so I apologize in advance for my ignorance. I'm just doing this for fun, so I don't have any other means of instruction besides the web.

I'm trying to create a state capital quiz. My problem is trying to get the questions to come up in a random order without repeating. What I've done is create an array for the states, and a corresponding one for the capitals. I've also created 50 integers to be assigned a random number 1-50. These integers are used to determine the order of the questions.

I've gotten it to work on small scale. Yet even when only using 10 integers there can be a long delay waiting for the program to loop and make sure all integers get assigned a different number. When trying it with 50 integers it hasn't worked yet. I can't tell if it's because of programming error or an extreme delay. Here's a copy of my randomization code for the small scale.

I guess my question is, should there be a delay? Is there a more efficient way of going about this?

Public Class Form1
dim a as Integer
dim b as Integer
dim c as Integer
dim d as Integer
dim f as Integer
dim g as Integer
dim h as Integer
dim i as Integer
dim j as Integer
dim k as Integer
dim random as Integer

Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Do While (a = 0 or b = 0 or c = 0 or d = 0 or f = 0 or g = 0 or h = 0 or i = 0 or j = 0 or k = 0)
Randomize
random = Int((10 * Rnd) + 1)
a = random
Randomize
random = Int((10 * Rnd) + 1)
If random <> a then
b = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b then
c = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c then
d = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d then
f = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d and random <> f then
g = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g then
h = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h then
i = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h and random <> i then
j = random
Randomize
random = Int((10 * Rnd) +1)
If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h and random <> i and random <> j then
k = random
Randomize
random = Int((10 * Rnd) +1)

End If
End If
End If
End If
End If
End If
End If
End If
End If
Loop
Me.Label1.Text = a & " " & b & " " & c & " " & d & " " & f & " " & g & " " & h & " " & i & " " & j & " " & k
End Sub
End Class

Thanks in advance to anyone willing to help me.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2008 10:48 am 
Offline

Joined: Sat Aug 30, 2008 7:13 am
Posts: 3
Problem solved. I had to rearrange my If statements. Rather than enclose it all under one If, I changed it to.

Do While (a = 0 or b = 0 or c = 0 or d = 0 or f = 0 or g = 0 or h = 0 or i = 0 or j = 0 or k = 0 or l = 0 or m = 0 or n = 0 or o = 0 or p = 0 or q = 0 or r = 0 or s = 0 or t = 0 or u = 0 or v = 0 or w = 0 or x = 0 or y = 0 or z = 0 or aa = 0 or bb = 0 or cc = 0 or dd = 0 or ee = 0 or ff = 0 or gg = 0 or hh = 0 or ii = 0 or jj = 0 or kk = 0 or ll = 0 or mm = 0 or nn = 0 or oo = 0 or pp = 0 or qq = 0 or rr = 0 or ss = 0 or tt = 0 or uu = 0 or vv = 0 or ww = 0 or xx = 0 or yy = 0)
Randomize
random = Int((50 * rnd) + 1)

If a = 0 then
a = random
End If
Randomize
random = Int((50 * rnd) + 1)

If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h and random <> i and random <> j and random <> k and random <> l and random <> m and random <> n and random <> o and random <> p and random <> q and random <> r and random <> s and random <> t and random <> u and random <> v and random <> w and random <> x and random <> y and random <> z and random <> aa and random <> bb and random <> cc and random <> dd and random <> ee and random <> ff and random <> gg and random <> hh and random <> ii and random <> jj and random <> kk and random <> ll and random <> mm and random <> nn and random <> oo and random <> pp and random <> qq and random <> rr and random <> ss and random <> tt and random <> uu and random <> vv and random <> ww and random <> xx and random <> yy then
b = random
End If
Randomize
random = Int((50 * rnd) + 1)

If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h and random <> i and random <> j and random <> k and random <> l and random <> m and random <> n and random <> o and random <> p and random <> q and random <> r and random <> s and random <> t and random <> u and random <> v and random <> w and random <> x and random <> y and random <> z and random <> aa and random <> bb and random <> cc and random <> dd and random <> ee and random <> ff and random <> gg and random <> hh and random <> ii and random <> jj and random <> kk and random <> ll and random <> mm and random <> nn and random <> oo and random <> pp and random <> qq and random <> rr and random <> ss and random <> tt and random <> uu and random <> vv and random <> ww and random <> xx and random <> yy then
c = random
End If
Randomize
random = Int((50 * rnd) + 1)

If random <> a and random <> b and random <> c and random <> d and random <> f and random <> g and random <> h and random <> i and random <> j and random <> k and random <> l and random <> m and random <> n and random <> o and random <> p and random <> q and random <> r and random <> s and random <> t and random <> u and random <> v and random <> w and random <> x and random <> y and random <> z and random <> aa and random <> bb and random <> cc and random <> dd and random <> ee and random <> ff and random <> gg and random <> hh and random <> ii and random <> jj and random <> kk and random <> ll and random <> mm and random <> nn and random <> oo and random <> pp and random <> qq and random <> rr and random <> ss and random <> tt and random <> uu and random <> vv and random <> ww and random <> xx and random <> yy then
d = random
End If
Randomize
random = Int((50 * rnd) + 1)

etc.

I kept that going for 50 integers with a loop at the end. There is absolutely no delay.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User:
Pass:
Log me on automatically each visit: