A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Powerpoint
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Random number again



 
 
Thread Tools Display Modes
  #1  
Old March 12th, 2010, 01:20 PM posted to microsoft.public.powerpoint
Preschool Mike[_2_]
external usenet poster
 
Posts: 102
Default 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  
Old March 12th, 2010, 01:24 PM posted to microsoft.public.powerpoint
Preschool Mike[_2_]
external usenet poster
 
Posts: 102
Default 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  
Old March 12th, 2010, 02:14 PM posted to microsoft.public.powerpoint
Mark[_59_]
external usenet poster
 
Posts: 72
Default 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  
Old March 12th, 2010, 02:26 PM posted to microsoft.public.powerpoint
John Wilson
external usenet poster
 
Posts: 6,023
Default 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  
Old March 12th, 2010, 03:06 PM posted to microsoft.public.powerpoint
Preschool Mike[_2_]
external usenet poster
 
Posts: 102
Default 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  
Old March 12th, 2010, 03:10 PM posted to microsoft.public.powerpoint
Preschool Mike[_2_]
external usenet poster
 
Posts: 102
Default 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  
Old March 12th, 2010, 04:28 PM posted to microsoft.public.powerpoint
John Wilson
external usenet poster
 
Posts: 6,023
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.