Jump to content

[LE] Is papyrus function Utility.RandomInt(x, y) inclusive for x too?


unblest

Recommended Posts

Hello. I tried searching randomint on the nexus forums but none seems to give me a clear answer.

According to creationkit's reference http://www.creationkit.com/RandomInt_-_Utility utility.randomint for example utility.randomint(0,5) would return one value from set of integers {1,2,3,4,5}, but is {0} included as well and return one from {0,1,2,3,4,5}?

I'm asking this because I've seen tons of mods that uses randomint(x, y) as if x is exclusive

 

Link to comment
Share on other sites

Answering my own question, but I ran

scriptname myfirstscript extends quest

Event OnInit()
string final = ""
string random = ""
int i=10
while i>0
random = utility.randomint(0,5) as string
final = final+", "+random
i -= 1
endwhile
Debug.Notification(final)
EndEvent

 

and string final does include 0

Link to comment
Share on other sites

  • 4 weeks later...

So, does RandomInt() generate a uniform distribution? What about RandomFloat()? I was hoping to find a utility function to generate a normal (Gaussian) distribution, where I initialize it with a seed value and a standard deviation. Does such an API exist or am I SOL?

Link to comment
Share on other sites

  • 5 years later...

So, does RandomInt() generate a uniform distribution? What about RandomFloat()? I was hoping to find a utility function to generate a normal (Gaussian) distribution, where I initialize it with a seed value and a standard deviation. Does such an API exist or am I SOL?

Sorry for digging up an old thread, but I had the same question some time ago. To get a (pseudo) normal distribution you just need to sum at least 4 flat distributions. For example if you want a Gaussian-like distribution between 0 and 100 you would do something like

 

float x = Utility.RandomFloat(0,25)+Utility.RandomFloat(0,25)+Utility.RandomFloat(0,25)+Utility.RandomFloat(0,25);

Edited by TrollAutokill
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...