# llFrand Help - Easy fix, i assume.

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

integer  highcheck = 5969

integer lowcheck = 4132;

Amount = llFloor(llFrand(highcheck) + lowcheck);

Can someone please explain to me... why the outcome of this line of script would be 7021?

I am trying to make it pull a random number between 4132 and 5969. Can't seem to figure out what im doing wrong.

##### Share on other sites

Try  Amount = llFloor( llFrand( -lowcheck ) + highcheck );

See https://wiki.secondlife.com/wiki/LlFrand .  You want the outcome of llFrand to be some negative number between 0 and -lowcheck.

##### Share on other sites

2 minutes ago, Rolig Loon said:

Try  Amount = llFloor( llFrand( -lowcheck ) + highcheck );

So this seemed to solve it from going ABOVE my high check...
but now im seeing 2000's

##### Share on other sites

2 hours ago, TessaAnnaMarie said:

integer  highcheck = 5969

integer lowcheck = 4132;

Amount = llFloor(llFrand(highcheck) + lowcheck);

Can someone please explain to me... why the outcome of this line of script would be 7021?

I am trying to make it pull a random number between 4132 and 5969. Can't seem to figure out what im doing wrong.

If you check the documentation, llFrand(x) returns a number between 0 and x, inclusive of 0, but exclusive of x.

In your case, a number greater than or equal 0, but smaller than 5969.

Then you add to that, the number of 4132.

If llFrand(x) returned 2889 -- which is still between 0 and 5969 btw -- then of course you'll get 7021 ( == 2889 + 4132).

If you want an integer number between "low" and "high", inclusive at both ends, you have to do it like this:

`    llFloor(llFrand(high-low+1)) + low`

Basically, you convert the inclusive range of [4132, 5969] into 4132 + [0, 1837]

But because llFrand is exclusive of the end value, you have to make the range into [0, 1838)  <== note the right value is now exclusive.

That is why there's a "+1" there. Because high-low+1 == 5969 - 4132 + 1 == 1838

Edit: The notation [x, y] means a range of numbers inclusive of x and y.  [x, y)  means a range of number inclusive of x, but exclusive of y. Pay close attention to the ending character; the first one uses a right bracket ] , the second one uses a right paren )

Edited by primerib1
##### Share on other sites

9 minutes ago, primerib1 said:

If you check the documentation, llFrand(x) returns a number between 0 and x, inclusive of 0.

In this case, a number greater than or equal 0, but smaller than 5969.

Then you add to that, the number of 4132.

If llFrand(x) returned 2889, which is still between 0 and 5969 then you'll of course end up with 7021.

If you want an integer number between "low" and "high", inclusive at both ends, you have to do it like this:

`llFloor(llFrand(high-low+1)) + low`

Basically, you convert the inclusive range of [4132, 5969] into 4132 + [0, 1837]

But because llFrand is exclusive of the end value, you have to make the range into [0, 1838)  <== note the right value is now exclusive.

Edit: The notation [x, y] means a range of numbers inclusive of x and y.  [x, y)  means a range of number inclusive of x, but exclusive of y. Pay close attention to the ending character; the first one uses a right bracket ] , the second one uses a right paren )

I solved it with this
integer temp = highcheck - lowcheck;
integer addnumber = llFloor( llFrand( temp )  +1 );
llSay(0, (string)Amount);

Thank you Been fighting this part of the script all day! Lol

##### Share on other sites

15 minutes ago, TessaAnnaMarie said:

I solved it with this
integer temp = highcheck - lowcheck;
integer addnumber = llFloor( llFrand( temp )  +1 );
llSay(0, (string)Amount);

Thank you Been fighting this part of the script all day! Lol

Your solution will cause the number to never hit the "lowcheck" value.

Because llFrand(temp) + 1 cannot go lower than 1.

Hence the lowest number Amount can reach is lowcheck + 1.

Rather, use llFrand(temp + 1) instead.

Extend the range instead of shifting the result.

Edited by primerib1
• 1
##### Share on other sites

3 hours ago, primerib1 said:

Your solution will cause the number to never hit the "lowcheck" value.

So this makes sense. And i know you should be right.
But for some reason, my script is doing **Exactly** what i need it to do. Lol

##### Share on other sites

3 hours ago, TessaAnnaMarie said:

So this makes sense. And i know you should be right.
But for some reason, my script is doing **Exactly** what i need it to do. Lol

Sure it works in that it solves your original problem of "going higher than the high limit".

Just be aware that it will never hit the low limit.

##### Share on other sites

there is also a function just for this on the Frand wiki page

```integer random_integer(integer min, integer max)
{  return min + (integer)llFrand(max - min + 1);
}```

• 1
• 2