I'm trying to run below vbscript in Linux using Wine, but it doesn't work. Other vbscript functions are working as expected.
Wine Version : wine-5.0.3 (Ubuntu 5.0.3-3) Command : wine cscript ./test_rnd.vbs
VBS:
On Error Resume Next
WScript.Echo "Before Rnd"
Rnd -1
WScript.Echo "After Rnd"
If Err.Number <> 0 Then
WScript.Echo "Error : " & Err.Number & ": " & Err.Description
End If
OutPut using Wine:

This script is working fine in Windows.
Do i need to install any other wine dependency ? if you have any alternative solution to execute VBS in Linux please mention.
The Rnd() function is dependent on seeds generated by the Randomize statement which generates seeds via the OS System Timer, a Windows OS feature. While Linux will have something similar, VBScript's code base will not know how to call it and will depend on Wine to provide an implementation that mimics the Windows System Timer.
As the error you are receiving is
Object doesn’t support this action
I’m afraid you’re out of luck until Wine provides an implementation.
Although it does not appear Wine supports VBScript's Rnd function, what about your own implementation of a "random" function with something like this?
Function RndNum(MaxValue)
RndNum = (((Hour(Now) + 1) * (Minute(Now) + 1) * (Second(Now) + 1) * Right(Timer, 5)) Mod MaxValue)
End Function
How to manually generate random numbers
Edit:
The above code did not generate random numbers when ran in a loop, as the timestamp is not precise enough.

Updating the function to use an external Seed does work, however I would not not vouch for how unique these would be, I'm assuming this would not be for Cryptography...
Function RndNum(Seed, MaxValue)
RndNum = (((Hour(Now) + 1) * (Minute(Now) + 1) * (Second(Now) + 1) * Right((Seed * Right(Timer, 5)), 8)) Mod MaxValue)
End Function
Do
counter = counter + 1
Numbers = Numbers & RndNum(counter,1000) & ", "
Loop While counter < 10
MsgBox Numbers

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With