Can RNDF() return 0? (Page 1) ● SmileBASIC Source Forums

Register

# Can RNDF() return 0?

• #1 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself RNDF() returns a random number >=0 and <1. It's technically possible for it to be 0, but this is EXTREMELY rare. If someone can find a situation where RNDF() returns 0, they'll win a prize. It has to be repeatable, like: ```RANDOMIZE 0,14522 TEMP = RND(7) PRINT RNDF()``` Good luck. Posted
• #2 ✎ 194 Nathaniel OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! OSP Contest 3 Contest Participant I participated in the third SmileBASIC Source OSP Contest! ```RANDOMIZE 0,14532 FOR I=0 TO 3 IF RNDF() THEN ENDIF NEXT ?RNDF()``` Posted
• #3 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself
```RANDOMIZE 0,14532 FOR I=0 TO 3 IF RNDF() THEN ENDIF NEXT ?RNDF()```
Close, but: ```RANDOMIZE 0,14532 FOR I=0 TO 3 IF RNDF() THEN ENDIF NEXT ?FORMAT\$("%.9F",RNDF()) '0.000000003```
Posted
• #4 ✎ 194 Nathaniel OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! OSP Contest 3 Contest Participant I participated in the third SmileBASIC Source OSP Contest! Maybe- ```RANDOMIZE 0,55219 FOR I=0 TO 2768 IF RNDF() THEN ENDIF NEXT ?FORMAT\$("%.9F",RNDF()) '0.000000000``` Posted
• #5 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Just check if it's actually equal to 0. That's 0.00000000019. Posted Edited by 12Me21
• #6 ✎ 194 Nathaniel OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! OSP Contest 3 Contest Participant I participated in the third SmileBASIC Source OSP Contest! Oh... now I see the impossibility of RNDF() ever returning exactly zero. I've gotten it to return up to 25+ random decimal places. And even if all of those just happened to be zero, at least to my findings, the number will just be shifted down about another 18 decimal places (essentially making no progress). Posted
• #7 ✎ 1057 snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements If we assume that the source of randomness in SB is a pseudorandom bit generator, then the odds are something like 1 to 2^52 of getting a zero. We don't know this definitely though and I'm just going off limited knowledge so the challenge is just finding the right seed. It's possible that there isn't a seed that gets zero on the first try but I don't know enough to say so. Posted
• #8 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself The number of floats in [0,1) is 2^52 * 1023 + 1 Anyway, I've checked and otyaSB's random number generator appears to act identically to SB's, so that might be a good way to find out how SB works. Posted Edited by 12Me21
• #9 ✎ 14 Hylian pfff just do `?RNDF() * 0` Posted
• #10 ✎ 44 Joshuaham123 I got it. `PRINT "RNDF()=0"` Posted Edited by Joshuaham123
• #11 ✎ 406 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website Don't know if this counts, but theoretically, RNDF() will always return 0 when the program ends with this code: ```NUM=1 WHILE NUM!=0 NUM=RNDF() WEND``` Basically this program will run over and over again until RNDF() returns 0, so it's (technically) repeatable, but it will take a REALLY long time for it to do so. Posted Edited by HTV04