I cant seem to generate a random number using MODULE cerberus.random

Lesther

New Member
Joined
Aug 3, 2018
I don't know how to generate a random number here. I've only used python before and Cerberus X feels very different and I can't get my head around some of the simple stuff. Can someone help me with this pls. I only get 0,1,3 as a result

Global Seed:Int



Function Main()

Seed=1237

Local asd:Float = Int(Rnd())

Local baz:Float = Int(Rnd(5.0))

Local foo:Float = Int(Rnd(0.0,5.0))

Print asd

Print baz

Print foo

End
 

magic

Active Member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Could you tell me the problem. All random number look good.
You don't need to declare a 'Global Seed:Int'. It will override internal global.
 

Holzchopf

Moderator
Staff member
Joined
Jul 31, 2017
Location
Bern, Switzerland
The pseudo random number generator generates a sequence of numbers based on the seed value. This means, if you set seed to the same value at every start up of your program, it will generate the same sequence every time.

A very common way to set the seed is writing
Code:
Local date := GetDate()
Seed = date[3] * 3600000 + date[4] * 60000 + date[5] * 1000 + date[6]
This way, you will see different results every time you run your code.
 

Lesther

New Member
Joined
Aug 3, 2018
Oh I get it now. I've only used python before so the idea of using a seed when generating a value is very new to me.
 

Raph

New Member
Joined
Aug 25, 2017
Python does seeding by the time automatically, but you can do random.seed() to set it manually.

Fixed seeds are useful for doing procedural generation; since you always get the same numbers back from the seed in order, you can basically store a whole level (or other procedurally generated thing) with just the seed number.
 
Top Bottom