Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Import Random function to Autoit

$
0
0
Hello.

Time ago, looking examples in the forum, I wrote a little script that looks for the mp3 and wav files in @scriptsfolder and plays one of them randomly:
[ autoit ]         
#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <ButtonConstants.au3> #include <Sound.au3> #include <File.au3> GUICreate("PRESS ESCAPE TO CLOSE SOUND PLAYING", 560, 380, -1, -1) GUISetState(@SW_SHOW) GUICtrlCreateLabel("PRESS ESCAPE TO CLOSE SOUND PLAYING", 30, 40, 500, 300, $SS_CENTER) GUICtrlSetFont(-1, 50, 10, 0)AutoItSetOption ( "GUIOnEventMode", 1) GUISetOnEvent ( $GUI_EVENT_CLOSE, "On_Exit" ) Func On_Exit() Exit EndFunc ;==>On_ExitHotKeySet("{ESC}", "On_Exit") $folder = @ScriptDir$list = _FileListToArray($folder, "*.mp3|*.wav", 1) For $iX = 1 To $list[0] $song = _SoundOpen($folder & "\" & $list[$iX]) _SoundPlay($song) Do Sleep(100) Until _SoundStatus($song) = "stopped" _SoundClose($song) canciones() Next While 1 $nmsg = GUIGetMsg() Select Case $nmsg = $GUI_EVENT_CLOSE On_Exit() EndSelect WEnd Func canciones() For $iX = 1 To $list[0] $song = _SoundOpen($folder & "\" & $list[$iX]) _SoundPlay($song) Do Sleep(100) Until _SoundStatus($song) = "stopped" _SoundClose($song) canciones() NextEndFunc ;==>canciones

Later talking with a friends he said me that:


Quote

I found out that my random numbers I generate with my program are not THAT random, ... it's hard to explain, since it's all random there are no real facts, but only a feeling after lot's of testing.
And the feeling says that it's not totally random as in "the law of random", ... it's just had too many of the same random numbers.

Then I googled and found a solution which works now fine for me, ... when I create a random number it looks like this in C# code:

Quote

Random randomNumber = new Random();
int newRandomNumber = randomNumber.Next(1, 101);

The fix which makes the randomness even more random is this:

Quote

Random randomNumber = new Random(Guid.NewGuid().GetHashCode());
int newRandomNumber = randomNumber.Next(1, 101);

I have exchanged every "new Random();" with that and now it "feels" much more random.

He asked me if I was able to port his code to my little Autoit script to generate random number, but my random number comes from the number of sound files found in the script's folder and his code comes from Guid.newGuid() and from GetHashCode() and always based on a number from 1 to 100.

Is there any way to implement his code into mine's?

Thanks in advance.

Greets from Barcelona

(Now I have to go to work, so I will edit the post later trying to be more polite)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>