VBA randomizing-avoiding negative numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can't figure out a code that randomly selects 2 numbers to subtract, 0-10,
where first number is always larger than the second number. ppt 2003
 
Try this:

a = Int(Rnd * 10)
b = Int(Rnd * a)

' a - b will always be => 0
' a will be 0-10
' b will be <= a


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
yahoo2@ Please read the PowerPoint
yahoo. FAQ pages. They answer most
com of our questions.
www.pptfaq.com
..
..
 
That's good and will work, but I think that it will give a higher
proportion of lower numbers. How about something like:

a = Int(Rnd * 10)
b = Int(Rnd * 10)
If a > b Then
firstNubmer = a
secondNumber = b
Else
firstNumber = b
secondNubmer = a
EndIf

With this, firstNumber - SecondNumber is always greater than or equal to
0 and, I think, the numbers will be more evenly distributed.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
Would this do it (where b is the larger)

a = Int(Rnd * 9) 'if b is larger a cannot be 10??
b = Int((10 - a) * Rnd + (a + 1))'b is in range a+1 to 10
 
Interesting ...

In charting it out... in my model the slope of the first number (a) is flat
and the slope of b is very negative crossing the x axis at about 8.

In your model the slopes are more evenly distributed and mirrored images of
one another. Even with all that, in a 5000 example sample this is the way
they differences between the numbers broke out

Difference meth 1 meth 2
0 494 526
1 1393 912
2 941 774
3 662 724
4 479 595
5 398 534
6 264 359
7 190 292
8 121 194
9 58 90

Total 5000 5000


Good call David, but I gotta get out of these stats meetings.

Bill D.
 
Wonderful- So simple yet so elusive!! I'm creating an interactive ppt. for my
kindergarteners to learn math facts in a given time.
THANKS
 
Back
Top