Nack Voom
Registered User
Join date: 6 Jan 2009
Posts: 5
|
12-13-2009 11:34
Hello, I am trying to create a script that uses llFrand(6) and will only output 4 random integers. I am able to output the random integers, but the problem is I get repeats  . Here is part of my code: while (x<4) { a = (integer)llFrand(6); llOwnerSay((string)a); x += 1; } My output is something like: "3.000000" "2.000000" "3.000000" "1.000000" What do I do to get rid of these repeats?
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
12-13-2009 11:50
You could make a list of the numbers, randomise it using llListRandomize, and then deal out the numbers from the list. ETA: list numbers = [0, 1, 2, 3, 4, 5];
default { touch_start (integer count) { llOwnerSay (llList2CSV (llListRandomize (numbers, 1))); } }
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
12-13-2009 12:48
list numbers =[1, 2, 3, 4, 5, 6];//Dice?
default { touch_start(integer count) { list trimList = llList2List(llListRandomize(numbers, 1), 0, 3); llOwnerSay(llList2CSV(trimList)); } }
returns: _temp1: 2, 1, 6, 5 _temp1: 2, 3, 6, 1 _temp1: 5, 1, 4, 6 _temp1: 3, 6, 2, 1 _temp1: 1, 2, 5, 3
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
12-13-2009 15:42
PS
(integer)llFRand( 6.0 )
will yield 0-5,
(integer)llFRand( 6.0 ) + 1
will yield 1-6
llFRand generates numbers in a range of [0, x)
that means any fraction up to but not including the number you input, and since casting to integer removes the fractional part, you can never get an integer of your input size, unless you add 1 to it.
another way to look at it, is that your input number is the number of possible choices, and your addition will be the first number in that possible sequence
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|