Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. string gsRndSeed = "asdf";
  2.  
  3. list glTest = [1,2,3,4,5];
  4. integer giCount = 0;
  5.  
  6. integer RndInt(integer iMax)
  7. // Zero to iMax returned.
  8. // The gsRndSeed is used.
  9. // An initial value (of anything) can be set as the initial seed.
  10. // This gsRndSeed can be reset to produce the same set of random numbers again.
  11. {
  12. gsRndSeed = llSHA1String(gsRndSeed);
  13. integer i = (integer)("0x" + llGetSubString(gsRndSeed, 0, 7)) & 0x7fffffff;
  14. return i % (iMax + 1);
  15. }
  16.  
  17. list RandomizeList(list lInput)
  18. // This uses the RndInt function for randomizing.
  19. // Set gsRndSeed before coming in if you want to control the initial seed.
  20. // This uses swapping, so there's no guarantee that it will be the fastest method.
  21. {
  22. integer i;
  23. integer j;
  24. list l;
  25. integer iEnd = llGetListLength(lInput) - 1;
  26. //
  27. for (i = 0; i <= iEnd; i++)
  28. {
  29. j = RndInt(iEnd);
  30. l = llList2List(lInput, i, i);
  31. lInput = llDeleteSubList(lInput, i, i);
  32. lInput = llListInsertList(lInput, l, j);
  33. }
  34. return lInput;
  35. }
  36.  
  37. default
  38. {
  39. touch_start(integer total_number)
  40. {
  41. giCount++;
  42. if (giCount == 3)
  43. {
  44. giCount = 0;
  45. gsRndSeed = "asdf";
  46. glTest = [1,2,3,4,5];
  47. llOwnerSay("Starting over");
  48. }
  49.  
  50. glTest = RandomizeList(glTest);
  51. llOwnerSay((string)glTest);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement