Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Need help with Rand()
Need help with Rand()
2002-07-12, 1:15 PM #1
Does anyone here know of a way to have JK choose a random number with only 4 possible outcomes?>

(Preferably the whole numbers 1 2 3 and 4, but anything will work, I suppose).

Any help here would be greatly appreciated.


Jedi_slayer_1
2002-07-12, 1:28 PM #2
Hi, remember me and my sabersystem. Okay, easy one. Rand()*4 and 4 is very rare what did SM say 1/75,000 I think. So your will get 0,1,2,3 and the extremly rare 4.

------------------
The Sniper Missions. Current project, The Sniper Missions
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-07-12, 1:43 PM #3
Using modulus:
Code:
value = Rand() * 4;
value = value - value % 1;


This will give you either 0, 1, 2, or 3. What do you need this for, BTW?

[edit] Just saw your post, Pilot. But Dynasty said "whole numbers." (Rand() * 4) is a flex between 0 and 4.

------------------
Author of the JK DataMaster, Parsec, and the EditPlus Cog Files.
Visit Saber's Domain.

[This message has been edited by SaberMaster (edited July 12, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-07-12, 1:59 PM #4
Yeah, that's what made it so odd [http://forums.massassi.net/html/tongue.gif]

My original idea used Rand()*4, but with no luck, so I'll try this.

This is for choosing a random direction for the button-presses of a dancing mod.

Thanks; I'll let you know if it works out.

Jedi_slayer_1
2002-07-12, 2:48 PM #5
Ah, that works beautifully.

Thanks for the help.


Jedi_slayer_1
2002-07-12, 6:09 PM #6
The simplest method is to make the random handler a INT..

Code:
Symbols
Int Random  Local
End
Code
//...
Random = Rand() * 4;
End



That truncates the unneeded digits.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.
2002-07-13, 2:23 AM #7
/me gives GBK five

Thats the way I have done it [http://forums.massassi.net/html/biggrin.gif]
Team Battle.
2002-07-13, 7:43 AM #8
Hate to burst your bubble, guys, but that doesn't work. JK will change the int to a flex and give it decimal digits. Use PrintFlex() and you'll see them.

------------------
Author of the JK DataMaster, Parsec, and the EditPlus Cog Files.
Visit Saber's Domain.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-07-13, 9:43 AM #9
Ive never had any trouble using that method, and Ive used it plenty.


Sure, its possible to change a variable's type, but when used in arrays, it works fine.

And if you think Im wrong, try using my method...


Setwallcel(Wall_0[Rand()*4], 0);


...Works just fine...

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.
2002-07-13, 11:15 AM #10
SaberMaster is saying that if you used PrintFlex(random); it would print out those decimal numbers. Yes we established it works that way in arrarys with my people.cog. But thats not what he's saying GBK.

------------------
The Sniper Missions. Current project, The Sniper Missions
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-07-13, 12:40 PM #11
I understand what he is saying, and I am not disputing it, but there are ways around it, and it isnt always a problem.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.
2002-07-14, 2:59 AM #12
Setwallcel(Wall_0[Rand()*4], 0); does work fine because JK ignores the flex portion of a number when it needs an integer value. But yeah, I see what you're getting at, GBK. [http://forums.massassi.net/html/smile.gif]

Good luck, Dynasty. [http://forums.massassi.net/html/wink.gif]

------------------
Author of the JK DataMaster, Parsec, and the EditPlus Cog Files.
Visit Saber's Domain.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!