How can I write this PHP rand() function in React.Js or in Nodejs/express.js

Please I am new in Javascript. I am trying to write this php rand() function in Javascript, I am building a project in React as frontend and Nodejs/express.js as backend.

I can solve the below code;

$rand = rand(1, 4);
            
if($rand == 1) {                
    duckPic = "resources/pic1.png";                 
} else if($rand == 2) {
    $profile_pic = "resources/pic2.png";
} else if($rand == 3) {
    $profile_pic = "resources/pic3.png";                
} else if($rand == 4) {
    $profile_pic = "resources/pic4.png";        
}