How to change the speed of a moving object randomely by code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bibin
:warning: Old Version Published before Godot 3 was released.
:bust_in_silhouette: Reply From: avencherus

randomize() to set a seed
randf() for a random float 0.0-1.0
randi() for a random int 0-1

Some of the code might look like:

var max_speed = 100
    
randomize()
var speed = randf() * max_speed
        
object.set_speed(speed)

How you implement set_speed is up to you. Most likely take a unit vector of it’s direction, and multiply the speed value into it’s X and Y components.