Rand() NOT work in Vista?
BlitzMax Forums/BlitzMax Programming/Rand() NOT work in Vista?
| ||
It seen random functions does not ramdom very well in some cause (does not known, why it dosent work here):Random 32 34 Random 33 34 Random 1 34 Random 2 34 it even I allready have seeded or not. Seed dosent work at all !! not even these lines below does not random as it should, all it does is just counting SeedRnd MilliSecs() Print Rand(0, 10) Other rand functions seen to do the same thing. |
| ||
I would guess you are seeding the generator before every call to to Rand. Millisecs() probably hasn't changed so neither does Rand. |
| ||
if I dosent use seedRnd, it allways print 5 out (just using Print Rand(0, 10)). By now I have simply needed to use a wrapper to use the Pure Basic version of it. It works a lots better. I guess it only on Vista (using 64bit version), not on XP and Linux. Haven't testet it on Linux. |
| ||
Post the loop that generated the first output |
| ||
And you might have a good point: Its most likely the 64bit, not even vista at all. XP64 already had some problems with 32bit emulation but Vista64 is an even worse thing. Did you try to run your app with xp sp2 emulation as admin. |
| ||
Post full sample code. |
| ||
I simply just compiled the one line code asPrint Rand(0, 10) and press Ctrl-R to compile it. Here it just allways output 5 (4 today) instead of random number every time I run it. Yes it might have due with 32bit emulation, since I use Vista 64bit OS. I use the PureBasic Random code, since it dosent seen to have effected it. I can't release it, due the politic not to release a Pure Basic command wrapper. Emulation as XP SP2 seen not to have a effect. |
| ||
Here it just allways output 5 (4 today) instead of random number every time I run it And?If all you are doing is running that again and again, then I would expect the possibility of the same number every time You implied that you had a loop that was giving the first posts results, can you please post that. (as youve been asked twice) |
| ||
And also, what do you get when you compile *just*: SeedRnd(millisecs()) Print Rand(0, 10) |
| ||
The real question is: What do you get when you use RND instead of RAND ... I would assume the error is there, if it isn't there, then you forgot to rebuild your modules on X64 and run into math problems on the multiplication or some similar problems due to 32Bit <-> 64Bit |
| ||
Print rand( 0,10 ) will indeed print the same thing every time - you must 'seed' the generator to receive different values. See brl.random module docs. In addition, seeding with millisecs in a tight loop wont work either, eg: For k=1 to 100 ...seedrnd millsecs() ...print rand... Next ...because millisecs is unlikely to have changed within the loop. |
| ||
|
| ||
I tried them all, but none diddent work here. I still it a Vista only bug (and even only in 64 bit vista), NOT on XP, because I remember it diddent have any issue on that and did works as normal. If I use SeedRND(), it just counting up by 1 to 3 numbers (about one per second), but never really random, like I shown in the first post (which was used when I tried to random my albums in my Jukebox application). Really wierd. |
| ||
triedFor k=1 To 100 SeedRnd MilliSecs() Print Rand(1,10) Next got 9 on all. Do I set a delay 100 in it, it count once per second. It more a timer than a random. ===== EDIT ===== If I do this: SeedRnd MilliSecs() Print Rand(1,10) Print Rand(1,10) THe first print is a "clock" and next one seen do a random as it should. |
| ||
In addition, seeding with millisecs in a tight loop wont work either, eg: For k=1 to 100 ...seedrnd millsecs() ...print rand... Next ...because millisecs is unlikely to have changed within the loop. |
| ||
And this?SeedRnd MilliSecs() For k=1 To 100 Print Rand(1,10) Next |
| ||
@Space Fractal: Why do you call SeedRnd() this often? Call it once on app's start and you're fine... |
| ||
I'm using Vista x64 and not having any problems with Rand() |
| ||
I asume, it the only first call, that react like a clock. If I call it again directly after, I got the random number.... So I just tested again normal application: If I call RAND function twice, it works. The first call is a clock and other calls do as it should. Strange. SeedRND above is just matter a test. Normally I only do that once per run and never per call. |
| ||
Can we PLEASE see the loop that is failing? not one that is like it... |
| ||
You should only need to be setting the seed once because further calls to Rand will also be setting it. |
| ||
It hard to make some code to reveke this bug, beause it seen only doing that on some machines, even using the same OS. Normally I allways seed it once, so I just used it here as test. I now just call it twice to make sure I got the random number. Simply: SeedRnd MilliSecs() Print Rand(1,10) Print Rand(1,10) (just recompile it again about once per second, as I do here) where second rand works as it should (but I need to seed it first, otherwice it dosent work. SeedRnd is NEED to get the second value to work, so it might been something work in seedrnd function and I use a danish version? Even I have seen a very simular bug in my older Arcade Music Box (BlitzPlus) when I tried to call bass.dll to change its volume. The first call did nothing, but the same call again got it to work. This is a long time ago.... The rest was seen to works fine. Strange. |
| ||
What does the first Rand return then? |
| ||
@Space And what does this give? SeedRnd MilliSecs() For k=1 To 100 Print Rand(1,10) Next @Support, Ban him, just ban him |
| ||
I guess I found what it really happens in the application: I have used seedrnd in each keypress, but do NOT do that. Use it ONLY on app or in game start. It seen it just the FIRST rand call after seedRND, that act like the clock. Rest works fine. To make sure, I might need to just call rand() once after seedrnd where it used, after then it works as it should. so it not in rand() that is a bug, but more than seedrnd(), that do not do autocall a rand() after a new clock seed. [EDIT] Examples what I did: Print "" Print "Fist digit act a clock, rest works fine" For i=1 To 5 SeedRnd MilliSecs(); a$="" For k=1 To 25 a$=a$+Rand(1,9) Next Print a$ Delay 1000 Next Print "This works fine, but added a dummy rand" SeedRnd MilliSecs(); dummy=Rand(1,2) For i=1 To 5 a$="" For k=1 To 25 a$=a$+Rand(1,9) Next Print a$ Delay 1000 Next Print "" Print "This works fine, but call rand() after seedrnd to jump clocking over" For i=1 To 5 SeedRnd MilliSecs(); dummy=Rand(1,2) a$="" For k=1 To 25 a$=a$+Rand(1,9) Next Print a$ Delay 1000 Next Output: Fist digit act a clock, rest works fine 3565481648696481443188513 4954199397197331318681177 4333628945598261184373632 5712348694889999859965296 6291957353382849735566661 This works fine, but added a dummy rand 5795769117837795912582341 7254435942415543786394691 9525332683175128389969812 4159258634351645463736264 1398143926189446291197334 This works fine, but call rand() after seedrnd to jump clocking over 6856733737899687693388564 1743929322818185359214212 4538116815826473916138851 8425394389845772762144499 3212591874854279428969138 |
| ||
What do you mean by acts like a clock? I don't notice anything odd. |
| ||
Right so you are saying that 3,4,4,5,6, isnt Random then. Even though you dont know what the number is going to be before you run it, and yet 5,4,3,2,1 (the forth call to rand) you say isRandom? Edit: Oh, what you are saying is that the first call to Rand after a seed is always the same number as the last first number after a seed, or is One higher. Well thats the way It also works in XP. It comes down to how the number is calculated/seeded. It is as ramdom as the other numbers because you simple dont know what the first value is, but if you seed a value 1000 more than last time thats what happens. Make the delay 10000, and see what happens. (Pay attention to the first two numbers) Now in a real situation you wouldnt know the first milli value, and it wouldnt normaly be a "Fixed" time unit before the next call. It is im afraid just the nature of the random generator |
| ||
I want to hurt you so badly... >_< |
| ||
This thread makes me laugh and cry at the same time. |
| ||
Fuck off with these spam :-(. PLEASE READ WHAT I WROTE. Thanks. Ran again: 9 896569857691251895461846 9 935716386641681637896876 1 664929377435463221977877 2 794266717585893953512798 3 824514247536342694937728 4 853751687576772435462759 5 692964668361554919543751 6 622212118422984751178771 6 752458548462434483593692 7 871715978423963234938632 8 911952428463493965454653 9 659266499257275549535654 1 779413848398625281169675 2 718659378358154923585615 3 838996718399584764929535 3 577211799184366347191537 4 617457239244796989636557 5 736694679284246721151588 6 866941119235675563586518 7 886287549285115394111449 It count appr. once per second. It simply fixing it by dummy call rand() once after seed. It really a simple workaround fix. |
| ||
Thread locked, and Space Fractal gets a free holiday due to coarse language. |