If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Random number again
I received help with the following code a few days ago and it works great for
what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. Thanks so much -- Mike Mast Special Education Preschool Teacher |
#2
|
|||
|
|||
Random number again
forgot to put in code on last post.
Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher |
#3
|
|||
|
|||
Random number again
On Mar 12, 8:24*am, Preschool Mike
wrote: forgot to put in code on last post. Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). *Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. *I've tried plugging numbers in here and there but not getting good results. *I would appreciate an explanation of how it works and help with correcting it for 24 numbers *so if future adjustments need to be made I can do them. * oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher- Hide quoted text - - Show quoted text - You should be able to just change the 12 to a 24 everywhere it appears (or better yet, set it to a variable and use that everywhere). I havent' looked at the code you are using too much, so I'm not quite sure why the one loop goes from 1 to 20. The code I posted earlier had the code to shuffle the array in a separate function, so you wouldn't have to rewrite it to handle a different sized array. If you use that, then you don't have to duplicate all of that code if you want to work with multiple different sized lists of numbers in the same program. |
#4
|
|||
|
|||
Random number again
Mike
In the code there are 5 occurrances of "12" - change them all to "24". -- john ATSIGN PPTAlchemy.co.uk Free PPT Hints, Tips and Tutorials http://www.pptalchemy.co.uk/powerpoi...tutorials.html "Preschool Mike" wrote: forgot to put in code on last post. Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher |
#5
|
|||
|
|||
Random number again
Thanks John that worked great. I thought I had tried that before I asked for
help but I must have left something out. -- Mike Mast Special Education Preschool Teacher "John Wilson" wrote: Mike In the code there are 5 occurrances of "12" - change them all to "24". -- john ATSIGN PPTAlchemy.co.uk Free PPT Hints, Tips and Tutorials http://www.pptalchemy.co.uk/powerpoi...tutorials.html "Preschool Mike" wrote: forgot to put in code on last post. Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher |
#6
|
|||
|
|||
Random number again
Thanks for you help Mark. The problem wasn't with your original code - It
was with me. I don't know a lot of vba (still in the learning process), especially how to use Functions - Plain and simple I didn't know how to use the code, still a lot to learn. -- Mike Mast Special Education Preschool Teacher "Mark" wrote: On Mar 12, 8:24 am, Preschool Mike wrote: forgot to put in code on last post. Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher- Hide quoted text - - Show quoted text - You should be able to just change the 12 to a 24 everywhere it appears (or better yet, set it to a variable and use that everywhere). I havent' looked at the code you are using too much, so I'm not quite sure why the one loop goes from 1 to 20. The code I posted earlier had the code to shuffle the array in a separate function, so you wouldn't have to rewrite it to handle a different sized array. If you use that, then you don't have to duplicate all of that code if you want to work with multiple different sized lists of numbers in the same program. . |
#7
|
|||
|
|||
Random number again
A function would be better but I figured harder for Mike to understand
The 1 to 20 just shuffles 20 times, enough to mix the numbers, you can add any reasonable number here. -- john ATSIGN PPTAlchemy.co.uk Free PPT Hints, Tips and Tutorials http://www.pptalchemy.co.uk/powerpoi...tutorials.html "Preschool Mike" wrote: Thanks for you help Mark. The problem wasn't with your original code - It was with me. I don't know a lot of vba (still in the learning process), especially how to use Functions - Plain and simple I didn't know how to use the code, still a lot to learn. -- Mike Mast Special Education Preschool Teacher "Mark" wrote: On Mar 12, 8:24 am, Preschool Mike wrote: forgot to put in code on last post. Sub SetRandomNumbers() Dim raynum(1 To 12) Dim i As Integer Dim Num_a As Integer Dim Num_b As Integer Dim Num_c As Integer Dim Num_d As Integer Dim stRresult As String 'fill the array For i = 1 To 12 raynum(i) = i Next i 'shuffle For i = 1 To 20 Randomize Num_a = Int((12 * Rnd) + 1) Num_b = Int((12 * Rnd) + 1) Num_c = raynum(Num_a) Num_d = raynum(Num_b) raynum(Num_b) = Num_c raynum(Num_a) = Num_d Next i For i = 1 To 12 stRresult = stRresult & raynum(i) & "/ " Next i MsgBox stRresult End Sub -- Mike Mast Special Education Preschool Teacher "Preschool Mike" wrote: I received help with the following code a few days ago and it works great for what I wanted (e.g. come up with 12 different random numbers). Now I'm trying to adjust it for something different (shuffle 24 different random numbers) but I don't understand how the code works. I've tried plugging numbers in here and there but not getting good results. I would appreciate an explanation of how it works and help with correcting it for 24 numbers so if future adjustments need to be made I can do them. oops forgot the code. Thanks so much -- Mike Mast Special Education Preschool Teacher- Hide quoted text - - Show quoted text - You should be able to just change the 12 to a 24 everywhere it appears (or better yet, set it to a variable and use that everywhere). I havent' looked at the code you are using too much, so I'm not quite sure why the one loop goes from 1 to 20. The code I posted earlier had the code to shuffle the array in a separate function, so you wouldn't have to rewrite it to handle a different sized array. If you use that, then you don't have to duplicate all of that code if you want to work with multiple different sized lists of numbers in the same program. . |
Thread Tools | |
Display Modes | |
|
|