Random number between 0 and 99 or string between 00 and 99

search tag # rextended random number generator

Random number between 0 and 99

:global randomnum do={
    /system resource irq
    :local tmpsum 0
    :foreach i in=[find] do={:set tmpsum ($tmpsum + [get $i count])}
    :set   tmpsum [:tostr $tmpsum]
    :local lentmp [:len   $tmpsum]
    :return [:tonum [:pick $tmpsum ($lentmp - 2) $lentmp]]
}

Random string between 00 and 99

:global randomstr do={
    /system resource irq
    :local tmpsum 0
    :foreach i in=[find] do={:set tmpsum ($tmpsum + [get $i count])}
    :set   tmpsum [:tostr $tmpsum]
    :local lentmp [:len   $tmpsum]
    :return [:pick $tmpsum ($lentmp - 2) $lentmp]
}

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 90 and generated random number 23

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 47 and generated random number 78

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 81 and generated random number 3

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 27 and generated random number 58

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 59 and generated random number 89

> :put “Generated random string $[$randomstr] and generated random number $[$randomnum]”
Generated random string 05 and generated random number 39

refreshed

I guess V6 never got :rndstr or :rndnum… But in V7, those are options for this too.

Yes, I’m all for feature equalization :wink:

Well :timestamp keeps moving along on V7, albeit slowly :wink:.

Bravo - IRQs…another cleaver one here.

Thanks…



Something really “random” and not repetable on reboot :laughing:
On 2021 the random on v7 not exist or not work… :wink:

And it’s not easier to get the same from:

:local tmpsum [/system resource get cpu-load]

?

The CPU can have the same load all the time,
so you would never get such different numbers,
but they would always fluctuate in the usual range like 9/10/9/10/11/9/10… etc.

I agree, this is usually observed in powerful devices. In weak soho, I see it fluctuates constantly in fairly large amplitudes.

4
[@MapliteRBM33G] > :put [/system resource get cpu-load]
2
[@MapliteRBM33G] > :put [/system resource get cpu-load]
70
[@MapliteRBM33G] > :put [/system resource get cpu-load]
13
[@MapliteRBM33G] > :put [/system resource get cpu-load]
2
[@MapliteRBM33G] > :put [/system resource get cpu-load]
2
[@MapliteRBM33G] > :put [/system resource get cpu-load]
3
[@MapliteRBM33G] > :put [/system resource get cpu-load]
11
[@MapliteRBM33G] > :put [/system resource get cpu-load]
47
[@MapliteRBM33G] > :put [/system resource get cpu-load]
11

Yes, on your example, 3 times “2” and 2 times “11”, and 2 times very close to the 2 (“3” and “4”)

If they are random it could happen, even once in a million, if not more, that the same number comes out 10 times in a row and over…
Why not?
But obviously one thing is the randomness, one thing is an excessive tendency to give the same numbers

You’re playing with “loaded” dice using the CPU. Do you really want 99 to come up as the random number?

But yes it is one line, but do think you’ll get “more randomness” from IRQ. But, yes its more lines of code.

This is why libraries for RSC are hard – everyone has difference preferences. If I actually had a need for a random number, in V6, and had internet… /tool/fetch to random.org would be even “more random”. Depending on ones formatting preferences, that could be one-line too.

The online version can be “offline” for some reason or you can need that on closed net…

I rewrite some minutest ago the OP and convert it to two distinct functions…
Only offline 6 lines for… v6 :wink:

(really… is only one line, the next are for formatting the result…)

I slightly changed the function of Rex’a and now I observe a strange thing: everything works from the terminal, but not from the script. :put [$randomnum] works, but log info [$randomnum] does not output anything… What’s the matter?


:global randomnum do={
    /system resource irq
    :local tmpsum 0
    :foreach i in=[find] do={:set tmpsum ($tmpsum + [get $i count])}
    :set   tmpsum [:tostr $tmpsum]
    :local lentmp [:len   $tmpsum]
    :return [:tonum [:pick $tmpsum ($lentmp - 2) $lentmp]]
}

:put [$randomnum]

:log info [$randomnum]