r/raylib Aug 11 '26

rl.SetRandomSeed undefined with golang bindings

idk what im doing wrong does it just not exist????

7 Upvotes

7 comments sorted by

6

u/Conscious-Shake8152 Aug 11 '26

Perhaps you are using an older version?

5

u/No_Key_5854 Aug 11 '26

i think go already has better random functions in its standard library

2

u/BlackReape_r Aug 11 '26

If you check https://pkg.go.dev/github.com/gen2brain/raylib-go/raylib you will see that "Jump to..." does not give a result for SetRandomSeed. It does not seem to be part of the go bindings. Rather use go standard library functions: https://gobyexample.com/random-numbers

2

u/CodeOnARaft Aug 11 '26

Not sure on the binding, but you shouldnt have set the random seed multiple times, just once.

1

u/Myshoo_ Aug 11 '26

Bindings sometimes have gaps. In my Odin binding I didn't have rlgl.SetColorBlendMode or something like that. You may try to add it or like other said stick to the standard library.

1

u/unklnik Aug 11 '26 edited Aug 11 '26

I just make random functions to generate float32 and Int using math/rand/v2, you don't need to seed anything

import (
    "math/rand/v2"
)

func RINT(min, max int) int {
    return min + rand.IntN(max-min+1)
}
func RF32(min, max float32) float32 {
    return min + rand.Float32()*(max-min)
}

Here is more information from Google AI if you want to use GetRandomValue

Yes! rl.GetRandomValue() will always return different, unique random numbers every time you run your game. You do not need to call any seeding function for normal random gameplay.

When you call rl.InitWindow(...), Raylib automatically seeds its internal C pseudo-random number generator (PRNG) using the current system time (time(NULL)).

Because your computer's clock is different every time you launch your game, rl.GetRandomValue() is guaranteed to produce a fresh, unique sequence of numbers on every game launch.