Random number generation with Meta Commands?

Hi all,
I was trying to make a simple random number generator  single digit, 9 to 9 numeric swing and came up with this:
echo floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))
Is there a better way to do this?
Cheers,
Kolbi

What's the use case? We could add a random number function if it would be generally useful.

@dc42 As of now I'm using it to offset prime line and working on making it used to offset prints starting location on the build plate.

Sorry @dc42, use case posted here: https://forum.duet3d.com/topic/17872/automaticbedlevelingwithconditionalgcodeiterations/62
Cheers,
Kolbi

Or to make a R2D2 impression...
while iterations <= 4 ; perform 5 passes M300 S{3000+(200*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} P{200+(10*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} M300 S{3000+(200*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} P{100+(10*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} G4 P200

@dc42 jumping on this one, I would find it quite useful if I could slightly randomise my z home position. I use a piezo nozzle contact to home Z and I have a ziflex magnetic build surface. I find that over time my Zoffset is drifting because repeated probing of the same point is putting an indent in the surface and damaging it.
I'm thinking if I could randomise the probing point within a given area (say a 10mm square) it would give me much less wear on the ziflex and shouldn't impact my z homing accuracy too much (by being in nearly the same place)

I would find it useful for randomly selecting pattern files to run on my sand table.

@dc42, here's the primeline macro  use case:
; 0:/sys/primeline.g ; Print primeline at a 'randomized' Y positon from 1.1 to 2.9 G1 X0 Z0.6 Y{2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0; G92 E0.0 ; set E position to 0 G1 Z0.2 X100.0 E30.0 F1000.0 ; prime line G92 E0.0 ; set E position to 0 M400 ; finish all current moves / clear the buffer
Cheers,
Kolbi