Repeatable Random Number
-
Well, you asked for advice, so I would check out what was suggested, but if you prefer to go with what you want, then sure, just type it in using Fuze syntax:
// declare random_seed somewhere as a global function myRand() random_seed = random_seed * 1103515245 + 12345 return (random_seed / 65536) % 32768
-
I'm sorry if I seem to have given the impression that I was ungrateful for the suggestion by pianofire. That was certainly not my intention. It's just that all code possibilities are worth exploring and some are better than others.
I have tried the suggested code - pianofire - and it runs flawlessly, Thanks... -
I have suggested that a way of setting the random seed be added to the language
-
Great! Thanks again.
-
Any news on the next update? Thanks.
-
You could loop through the length of a string? So like
for i = 0 to len(seed) loop
Seed[:i:] * (i*14)
RepeatThat way each number would return a set value. If you add more parameters it could output different numbers based on the scenario, but it'd be the same number per seed
(Also this is using the advanced text functions, more about them in the hints and tips section on this forum) -
I suspect you could use stringhash(value) to generate pseudo random numbers:
string seed = str(random(1000000000)) function rng(low, high) int value = stringhash(seed) seed = str(value) // following line limits "value" to be between high and low: value = (abs(value) % abs(high-low)) + low return value
EDIT: just checked, and similar numbers give similar patterns, so this might not be what you want.
For example, the results ofStringHash("0")
toStringHash("9")
are177621
to177630
(counting). However if your initial seed is random, the sequence of the example code above at least looks somewhat random to me... -
Deleted my Elite clone as it taking up too much time. Also the code was a complete mess. Now unfortunately, when I try to access the Map Editor or Image Editor Fuze closes "because an error occurred". I've done a Switch reboot but the problem remains. The crash also occurred when I made two copies of my original (approx. 800 lines) code. If I tried to reload and run the original file a crash would occur but I learnt to live with that. Could my two copies still be present somewhere? I've just loaded and run KatRacer ok. Back to tools and image editor - crash again. Any ideas, Sir. Thanks.
-
@faz808
Try creating a new project and putting in some basic code like load image, create sprite, variable =1, clear, update, repeat..
Then try.
Whilst we wait for a better assist -
Update. I've deleted all the downloaded examples (not the included examples!) and the problem has disappeared. One of the downloaded files was causing the crash. I had about a dozen so which one was causing the problem is anyone's guess.
-
I've just made two copies of a small Print "hello" program. No crashes. The problem was definitely caused by one of the downloaded code examples.
-
@faz808 Was this something you downloaded by entering a code or from a friend share?
-
Entering a code.
-
@faz808 OK I will see if I can identify the culprit
-
I should have removed them one by one and retested. Sorry about that.
-
@faz808 No problem
-
@faz808 Can you do me a favour please? Download Tanks (QXK7LRCQ9D) and see if this causes the problem.
-
Tanks loaded and run. No problems. Maybe it was my code. I had about 4700 star points plotted. Together with planet images. Maybe I was pushing my luck with memory requirements. And random planet names. I don't know. Just thinking out loud here. All seems ok now. I am going to rethink my Elite clone. Approach it from a diffent angle. Thanks
-
I deleted my 3d stars code in my eagerness to clear out downloaded code. Luckely under:-
Beginners / Array Problems - 17 days ago, I retreived it.
But ... I didn't notice the error ....
23 star0[i] = (random(50))-25
24 star1[i] = (random(50))-25
25 star2[i] = zdepthshould of course be:-
23 star0[pp] = (random(50))-25
24 star1[pp] = (random(50))-25
25 star2[pp] = zdepthHappy coding, John