logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Generating random values for non-integers (Read 149 times)
gopostal
Betatester
Offline


Retired

Posts: 728
Joined: Jul 31st, 2008
Gender: Male
Generating random values for non-integers
Nov 5th, 2017 at 10:22pm
Print Post  
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'm outta here. C ya!
Back to top
 
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 864
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Generating random values for non-integers
Reply #1 - Nov 6th, 2017 at 8:31am
Print Post  
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.
  
Back to top
 
IP Logged
 
gopostal
Betatester
Offline


Retired

Posts: 728
Joined: Jul 31st, 2008
Gender: Male
Re: Generating random values for non-integers
Reply #2 - Nov 6th, 2017 at 1:07pm
Print Post  
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'm outta here. C ya!
Back to top
 
IP Logged
 
Bleeder91[NL]
Betatester
Offline


Personal Text:

Posts: 911
Location: Location, Location, Location.
Joined: Oct 4th, 2009
Gender: Male
Re: Generating random values for non-integers
Reply #3 - Nov 7th, 2017 at 11:53am
Print Post  
Oh wow, I actually thought it was integers as well :\
  
Back to top
 
IP Logged
 
gopostal
Betatester
Offline


Retired

Posts: 728
Joined: Jul 31st, 2008
Gender: Male
Re: Generating random values for non-integers
Reply #4 - Nov 7th, 2017 at 2:09pm
Print Post  
I tested it in my code and it does fantastic. Thank you (yet again) MasterKent!
  

I'm outta here. C ya!
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo