For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Generating random values for non-integers

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Generating random values for non-integers

Post by gopostal »

Is there an easy way to do this with a function I'm just not aware of? I have an actor that is editor configurable and I want to generate a random value between two settings. This can often be as small as 0.01 and 0.06 (for example). Can this be done easily like it is with integers?
I don't want to give the end away
but we're all going to die one day
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: Generating random values for non-integers

Post by Masterkent »

Core.Object has function RandRange:

227:

Code: Select all

// Return a random number within the given range.
static final function float RandRange( float Min, float Max )
{
      return Min + (Max - Min) * FRand();
}
which returns a random float number from the range [Min, Max] (Min and Max are included in the set of possible return values).

In pre-227 versions and UT, this function is non-static.
Last edited by Masterkent on Mon Nov 06, 2017 8:34 am, edited 1 time in total.
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Re: Generating random values for non-integers

Post by gopostal »

Thank you. When I saw this right above it:

Code: Select all

// Return a random number within the given range.
in the source code I assumed it was for integers only. I should have tested it myself to see for sure.
I don't want to give the end away
but we're all going to die one day
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1062
Joined: Sun Oct 04, 2009 7:22 pm

Re: Generating random values for non-integers

Post by Bleeder91[NL] »

Oh wow, I actually thought it was integers as well :\
Image
User avatar
gopostal
OldUnreal Member
Posts: 1007
Joined: Thu Jul 31, 2008 9:29 pm

Re: Generating random values for non-integers

Post by gopostal »

I tested it in my code and it does fantastic. Thank you (yet again) MasterKent!
I don't want to give the end away
but we're all going to die one day

Return to “UScript Board”