Here is the simple Node.js code
var seed = 45;
var x = Math.sin(seed) * 0.5;
public String pseudorandom()
int seed = 45;
double num = Math.Sin(seed) * (0.5);
There is a note
The output of toFixed may be more precise than toString for some values because toString only prints enough significant digits to distinguish the number from adjacent number values. For example,
(1000000000000000128).toString()returns "1000000000000000100", while
Hence to get full digit accuracy you need something like
seed = 45; x = Math.sin(seed) * 0.5; x.toFixed(17); // on my platform its "0.42545176226705922"
Also, note the specification for how the implementation of sin and cos allow for some variety in the actual algorithm. It's only guaranteed to within +/- 1 ULP.
Using java the printing algorithm is different. Even forcing 17 digits gives the result as 0.42545176226705920.
You can check you are getting the same bit patterns using
Double.doubleToLongBits(x) in Java.