|
-
Apr 21st, 2001, 02:57 PM
#1
Thread Starter
New Member
I want to generate four random integers with a total sum of 100 like (12, 43, 18, 27) and then want to adjust the hight of four rectangle shapes in the same ratio i.e. 12:43:18:27.The above set of numbers is to be generated randomly to change the hight of rectangle shapes. What I actually want is to display a graph of 4 colums with random value in percentage.
Please help.
-
Apr 21st, 2001, 03:09 PM
#2
transcendental analytic
generate 4 numbers with RND function, with accuracy you choose, calculate their sum and divide it by 100 and you have the ratio which you divide each number with as a final. Use Int() function to truncate
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 22nd, 2001, 11:16 PM
#3
Registered User
kedaman,
Just wondering, if you are trying to get 4 integers which sum to 100, and you generated 4 random numbers where the following shows the % results:
number 1 : 23.3%
number 2 : 23.3%
number 3 : 24.3%
number 4 : 29.0%
------
100.0%
What would the 4 integer numbers be?
-
Apr 23rd, 2001, 04:13 AM
#4
transcendental analytic
23,23,24 and 29 would sum up 99, if you want to generate true random (that is equal chance for each number to have any value proportional to each other) then regenerate until you reach 100. Otherways you could add up the rest to a randomly choosed value.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 23rd, 2001, 02:45 PM
#5
Good Ol' Platypus
How 'bout this:
Code:
Dim A, B, C, D
A = Int(Rnd * 100)
B = Int(Rnd * 100)
Do
If A + B > 100 Then
B = Int(Rnd * 100)
End If
Loop Until A + B =< 100
C = Int(Rnd * 100)
Do
If A + B + C > 100 Then
C = Int(Rnd * 100)
End If
Loop Until A + B + C =< 100
D = Int(Rnd * 100)
Do
If A + B + C + D > 100 Then
D = Int(Rnd * 100)
End If
Loop Until A + B + C + D =< 100
And there you have it!!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 23rd, 2001, 03:02 PM
#6
transcendental analytic
thats definitely biased to give higher values for A and B
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 24th, 2001, 11:00 AM
#7
Frenzied Member
Try this:
Code:
Dim Total, Temp, Val(1 to 4), CurVal
Total = 100
Do Until Total=0
Temp = Int(Rnd*1)
CurVal = CurVal + 1
If CurVal > 4 Then Curval = 1
Val(CurVal) = Val(CurVal) + Temp
Total = Total - Temp
Loop
Heh, hope that works
-
Apr 24th, 2001, 11:14 AM
#8
transcendental analytic
biased to give values close to 25
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 24th, 2001, 03:05 PM
#9
Frenzied Member
Ok, ok: this one should work 
Code:
Dim Total, Temp, Val(1 to 4), CurVal
Total = 100
Do Until Total <= 0
Temp = Int(Rnd*25)
If Temp > Total Then Temp = Total
CurVal = CurVal + 1
If CurVal > 4 Then Curval = 1
Val(CurVal) = Val(CurVal) + Temp
Total = Total - Temp
Loop
Try it out. It generates completely random numbers
Last edited by Jotaf98; Apr 24th, 2001 at 03:09 PM.
-
Apr 24th, 2001, 03:23 PM
#10
transcendental analytic
Give up, and save yourself some time
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Apr 29th, 2001, 01:47 PM
#11
Thread Starter
New Member
Thanks for the help extended to me. I succeeded in doing it throgh the following code.
Randomize
Cls
JA0 = Int((101 * Rnd) + 1)
JA1 = Int((101 * Rnd) + 1)
JA2 = Int((101 * Rnd) + 1)
JA3 = Int((101 * Rnd) + 1)
JT = JA0 + JA1 + JA2 + JA3
JS0 = Int((JA0 / JT) * 100)
JS1 = Int((JA1 / JT) * 100)
JS2 = Int((JA2 / JT) * 100)
JS3 = Int((JA3 / JT) * 100)
JH0 = Int((JS0 * 120 * 31) / 100)
JH1 = Int((JS1 * 120 * 31) / 100)
JH2 = Int((JS2 * 120 * 31) / 100)
JH3 = Int((JS3 * 120 * 31) / 100)
FrmPubopn!Shape1.Top = 3720 - JH0
FrmPubopn!Shape2.Top = 3720 - JH1
FrmPubopn!Shape3.Top = 3720 - JH2
FrmPubopn!Shape4.Top = 3720 - JH3
FrmPubopn!Shape1.Height = JH0
FrmPubopn!Shape2.Height = JH1
FrmPubopn!Shape3.Height = JH2
FrmPubopn!Shape4.Height = JH3
FrmPubopn.Show
End Sub
What I have done-
Generate 4 random nos range 0 to 100.
get their sum.
Devide each no by the sum and multiply by 100 to get percentage.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|