Handy random number generator (not cryptographically strong, just trivial)

Share actions you've created here.
Post Reply
Posts: 8
Joined: Wed Jul 27, 2011 1:52 pm

Handy random number generator (not cryptographically strong, just trivial)

Post by Jesse » Tue May 29, 2018 4:09 pm

Sometimes my roommate and I are coding up something in Secondlife, and we need a large random number to hardcode a channel not likely to be used by anybody else. It would be handy to just have a 3Dclip action to choose such a number for us, so I made one. :)

Code: Select all

Dim max,min
If(IsNumeric(clipboard.value)) Then
End If
clipboard.value = CStr(Int(max*Rnd))
Use: first, prepare an integer in the clipboard you want to act as a "Max" such that 0 <= random integer < Max

For example, if you choose 10 you may get anything 0..9. I am a programmer, so counting from zero and not counting the cardinal is just how I roll. But if you want to count from 1 and include the cardinal (EG 1..10), just tack a +1 onto the end of the final line of code.

Then apply this action to that "max" value and the fresh random integer value will be put into your clipboard.

As a bonus, if you choose a "max" that is not a number then this will just choose a max of one billion instead. That's a Fermi approximation of the the range we're normally working with in SL as channel is a signed 32 bit number, so it's convenient for us to not always have to specify the max value. If you'd like a different default max, just alter line 5.

Happy entropy folks! :9

Post Reply