vb6 - Different numbers from 1 to 10 -


I want to generate 10 different numbers from a range of 0- 9 The desired output can look like this, 908 6 5 3 2 4 1 7

as an integer in the form of an integer dimmer CRMD boolean dimming RMD as the slow array (9). = 0 to 9 arraynum (I) = -1 next ICRMD = true random timer I = 0 to 9 rmd = Int (Rnd * 10) for j = 0 to 9 if arraynum (j) = rmd Then j = 9 if crmd = false then i = I - 1 end if CRMD = True ALS CRMD = Fail End and GP = CRMD = false, then Arrayumum (I) = RMD QAlabel. Caption = Qualciillal Caption + str (arramum (i)) and if next I

selection of random values Doing and throwing those people that you have already used makes the run-time time because the pool of available numbers decreases because you are throwing more and more.

What you want is a shuffle list that I have the following code (this is homework since the post-code):

  dim n [10] // n [ 0] through n to n [9] each in 0..9: n [i] = i // start them to index them nsize = 10 // the size of the starting pool is 10 times: i = Rnd (nsize) give a number between 0 and nsize-1 n [i] nsize = nsize - 1 // The effectively used number of these two lines is n [i] = n [nsize]  

From the pool to a random number Reduce the size of the place and the pool with the number above the pool, you get a shuffle without the worry of a large number of swap-up front. It is important that if the number is high then that it does not delay an unnecessary startup presents. For example, check the following benchmark:

  & lt; - -------- n [x] ---------- & gt; X = 0 1 2 3 4 5 6 7 8 9 For NSICID RND (NSE) output --------------------------- --- - - ---------- ------ 0 1 2 3 4 5 6 7 8 9 10 4 4 0 1 2 3 9 5 6 7 8 7 7 1 1 2 3 5 5 6 6 8 8 2 2 0 1 8 3 9 5 6 7 6 6 0 1 8 3 9 5 6 0 5 1 8 3 9 5 2 8 5 1 9 3 4 1 1 5 3 3 3 3 5 5 5 9 3 2 1 3 9 You can at least see the pool, because you are keeping someone used as usual instead of unused one, you will never repeat.  

And Now In your homework this involves converting it to VB: -)


And, because this homework is almost certainly overdue (Almost a year ago), I will post a VBA S: How to do this altitude, it shows for perfection.

  A clear choice of option Base 0 all macro 1 () random dim list (10) as integer dim I integer dim size like integer dim position like integer dim I = 0 to 9 list ( I) = I next size = 10 result = ": for the result string as for string = 10 = 10 for position = int (rnd () * size) result = result & amp; list (position) & ; ":" Size = size - 1 list (status) = list (size) next message box result termination   

It is generated on three separate runs:

<5: 7: 4: 2: 9: 1: 0: 8: 3: 6 :: 3: 9: 6: 0: 7: 8: 5: 4: 2: 1 :: 7: 6: 3: 5: 1: 8: 9: 0: 4: 2:
< / Html>

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -