View Full Version : random case question...
footballjds
12-20-2007, 04:45 PM
here is the code:
begin
Case random (2) of
0: TypeSend('lets do this');
1: TypeSend('yay');
end;
end;
now what if i wanted it to do case 0 90% of the time? and case 1 only 10% of the time? how would i do this? i still want it to be random!
LordGregGreg
12-20-2007, 04:51 PM
i know this is kinda cheating... but i forget how to do the shortcut for cases without having to type in 1 , 2, 3, 4, 5, 6, 7, 8; (onl know it for java)
so the other way would be.
begin
if random (10) > 9 then
begin
TypeSend('lets do this');
end
else begin
TypeSend('yay');
end;
n3ss3s
12-20-2007, 04:52 PM
@Greg: desperate for syntax errors? ;)
LordGregGreg
12-20-2007, 04:54 PM
@Greg: desperate for syntax errors? ;)
!
lol, thanks, leavy my lazyness alone, lol
footballjds
12-20-2007, 05:18 PM
ok thanks.
anyone else know a way? other than ifs thens?
i so wish scar was written in JAVA! id have a much easier time!.....
mickaliscious
12-20-2007, 10:57 PM
There's the old classic:
case random (10) of
0,1,2,3,4,5,6,7,8: TypeSend('lets do this');
9: TypeSend('yay');
end;
But thats annoying. That and gregs way are the only ones I know.
footballjds
12-21-2007, 12:51 AM
ty! thats the one i wanted, thanks mick!
n3ss3s
12-21-2007, 11:00 AM
Well footballdjs got what he wanted, but I'll continue the discussion -
who said you have to use a case? ;)
program New;
Var
I: Integer;
begin
I := Random(100);
If I > 80 Then
Writeln('I was larger than 80')
Else
If I > 50 Then
Writeln('I was larger than 50, but smaller than 80!')
Else
If I > 20 Then
Writeln('I was larger than 20, but smaller than 50')
Else
If I >= 0 Then
Writeln('I was smaller than 20');
end.
Also, who said you couldn't make an array of procedure/function calls?
Then you will survive with a for loop.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.