|
Post by drfloyd on Jun 10, 2019 8:24:59 GMT -6
Hi Could you please try this : for i=1 to 100 hasardous=rand(90000) next for me the result never go up to (about) 30000....
|
|
|
Post by n00b on Jun 10, 2019 8:47:45 GMT -6
Add this line to the top of your code:
Randomize(Timer)
|
|
|
Post by drfloyd on Jun 10, 2019 11:14:42 GMT -6
I know
as it is a procedural game, i do not use the timer
Perhaps it is a code problem, i investigate
|
|
|
Post by drfloyd on Jun 10, 2019 13:29:42 GMT -6
Tested, there is a real bug. Random generator cannot go up to 32758
Same problem if i use randomize (timer) or randomize(x)
Check my test program :
' ****************************************************** MAIN ********************************************************
windowOpen(0,"COSMOS", 30, 30, 400,272,1)
CanvasOpen(0,400,272,0,0,400,272,1)
loadfont (1,"media/fonte6.ttf",8)
record=0 ' 32758 is the max
randomize (timer)
do
clearcanvas
test=rand(100000)
font(1)
setcolor (rgb(123,234,123))
drawtext (str(test),100,100)
drawtext (str(record),250,100)
if test>record then
record=test
end if
if key(k_escape) then
end
end if
update()
loop
|
|
|
Post by n00b on Jun 10, 2019 14:32:50 GMT -6
I looked into it. The rand function on Windows uses the VCRT (Visual C Runtime). For some reason microsoft still has this set to a max of 32767 in some versions of Windows. Check out this post on it: RAND_MAX in stdlib.hI actually never new this number had a low limit like this. I will try to have this fixed in the next release. Thanks for reporting it.
|
|
|
Post by drfloyd on Jun 16, 2019 10:54:04 GMT -6
the max 32767 is a little problem (but can be fixed when you have time)
there is another problem, more important, with RANDOMIZE()... which do no work very well.
For example if I do a randomize (123000) and generate a random number rand(32767)
and then do a randomize (123054) and generate a random number rand(32467)
and a randomize (215680)
etc....
you will see that the random numbers generated are very closed.... following a serial....
For my game it is a huge problem, as i can see non real random sequences on some game procedures.
Very "embarassing" (good englsh?) for COSMOS II
|
|
|
Post by n00b on Jun 16, 2019 11:05:57 GMT -6
In your situation you should be using Randomize(timer). There is almost never a reason to not use it. On computers there really is no such thing as truly random numbers. The randomize() function seeds the psuedo random generator. This is an algorithm that determines a random number based on the seed and then resets itself based on the seed. Its not a bug, its how every programming language deals with random numbers, even C++.
|
|
|
Post by drfloyd on Jun 16, 2019 12:13:31 GMT -6
yes but i don't want to use TIMER, because I raise a persistant-procedural game... with no hasard (the universe is the same for everybody)
In other langages the rand() give me real random series : 456, 123,984,12,9,701,89....
With RC the results sounds like 123,127,137,148,167,201,213,245.... more predictable.
I can see that visually on my prototype of COSMOS II with RC : there are "math structures" in the position of the stars in space
I need to find a solution (perhaps without using Randomize)
|
|
|
Post by n00b on Jun 16, 2019 12:40:16 GMT -6
Can you post an example from another language on what you are trying to do?
|
|
|
Post by drfloyd on Jun 16, 2019 13:12:40 GMT -6
an exemple : ' **** seed 20000 randomize (20000) for i=1 to 100 print rand(33000) next ' ***** seed 20001 randomize (20001) for i=1 to 100 print rand(33000) next with blitz the second loop generate new hasard numbers with RC, the second loop generate about the same numbers as first loop (it 's not a mathematic rule, but this problem come several times) I need a big panel of seed... billion seed to generate billion worlds.... if close seeds generate the same thing it is a problem... So i tried big seed, but without succes... for example a seed 120 000 300 seems to give about the same results as seed 121 100 308 perhaps i am not clear at all, in that case, ignore my query
|
|
|
Post by aurel on Jun 16, 2019 13:28:16 GMT -6
I think that nOOb have a right ,seed generator depend on C runtime functions. Blitz maybe use fractal generator to translate floating point numbers to INTEGERS and then you can use it on large scale.
|
|
|
Post by n00b on Jun 16, 2019 18:41:46 GMT -6
drfloyd I tried your example on windows and it was not generating even close to the same numbers. I also think that you should still be using either timer or some other seed for Randomize() that is not fixed. Otherwise those numbers will be the same every time you start the game. If you want those numbers to be fixed then I don't see why you are using Rand().
|
|
|
Post by n00b on Jun 16, 2019 20:24:27 GMT -6
You can generate higher random numbers with some bit shifting. Try this:
randomize(timer)
max_int = hexint("FFFFFFFF") low_bit = hexint("FF")
function hi_rand(n) return int( ( (rand(low_bit) shl 24) + (rand(low_bit) shl 16) + (rand(low_bit) shl 8) + rand(low_bit) ) / max_int * n ) end function
This function will allow you to generate a random number up to 4,294,967,295.
I am also still looking into generating higher random numbers on windows with Rand(). I have found ways of doing it but all of them are really slow compared to Microsofts Visual Runtime function that it is currently using. SDLBasic also seems to have the same limit on Windows as well. It will be addressed in the next released hopefully.
|
|
|
Post by drfloyd on Jun 17, 2019 9:06:36 GMT -6
my example was not good, but sometimes, randomize(x) or randomize(x+1), or randomize(x+2) give about the same result when I use RAND() rand(1000) can generate for exemple 745 (fully hasard number)... i change the seed+1, it will generate 747... very near…. it's not a bug, it's like this, i need to adapt myself And no, i cannot use TIMER... i need to enter specific Numbers into RANDOMIZE() Also, it seems that randomize() has perhaps some limitations with the max number. My problem is specific, I should be the only person in the world who need a better seed generator LOL... I have found an acceptable solution anyway
|
|
|
Post by drfloyd on Jun 24, 2019 0:27:20 GMT -6
thank you for the "Patch" NOOb ! The random generator has new rules, so I should update my program, but it is not a problem.
Random is working very well of course of usual use.
In my case i use each loop (about 60time per second) about 600 times the RANDOMIZE(nb) or sometimes RANDOMIZE(Timer) !!!!!
So the generator has apparently little difficulties in some situations to update impredictable numbers if the variable (nb) or (TIMER) are too close... it's obscur for me... But don't worry, i found solutions.
|
|