Jump to content

Recommended Posts

Posted

I was shocked when I found out that AutoIt did not have any random date function. I couldn't find that anyone else did it before so I made one because I needed it in one of my project.

#include <Date.au3>

ConsoleWrite(RandomDate("2008/01/01 00:00:00"))

Func RandomDate($Start)
    Local $Difference
    Local $rand

    If Not _DateIsValid($Start) Then 
        MsgBox(0, "Error", "The specified date is invalid.")
        Return ""
    Else
        $Difference = _DateDiff('s', $Start, _NowCalc())
        $rand = Random(0, $Difference, 1)
        Return _DateAdd('s', $rand, $Start) 
    EndIf
EndFunc
Posted

Good idea!!

to be "random"

#include <Date.au3>

ConsoleWrite(RandomDate("2008/01/01 00:00:00") & @CRLF)

ConsoleWrite(RandomDate("2008/04/01 00:00:00", "2008/05/01 00:00:00") & @CRLF)

Func RandomDate($Start, $End = "")
    Local $Difference, $rand
    If $End = "" Then $End = _NowCalc()

    If Not _DateIsValid($Start) Or Not _DateIsValid($End) Then
        MsgBox(0, "Error", "The specified date is invalid.")
        Return ""
    Else
        $Difference = _DateDiff('s', $Start, $End)
        $rand = Random(0, $Difference, 1)
        Return _DateAdd('s', $rand, $Start)
    EndIf
EndFunc   ;==>RandomDate

8)

NEWHeader1.png

Posted

Good idea!!

to be "random"

#include <Date.au3>

ConsoleWrite(RandomDate("2008/01/01 00:00:00") & @CRLF)

ConsoleWrite(RandomDate("2008/04/01 00:00:00", "2008/05/01 00:00:00") & @CRLF)

Func RandomDate($Start, $End = "")
    Local $Difference, $rand
    If $End = "" Then $End = _NowCalc()

    If Not _DateIsValid($Start) Or Not _DateIsValid($End) Then
        MsgBox(0, "Error", "The specified date is invalid.")
        Return ""
    Else
        $Difference = _DateDiff('s', $Start, $End)
        $rand = Random(0, $Difference, 1)
        Return _DateAdd('s', $rand, $Start)
    EndIf
EndFunc   ;==>RandomDate

8)

Nothing random comes out of there if I use it like this:

#include <Date.au3>

ConsoleWrite(RandomDate("2008/01/01 00:00:22", "2008/01/01 00:00:00") & @CRLF)

Func RandomDate($Start, $End = "")
    Local $Difference, $rand
    If $End = "" Then $End = _NowCalc()

    If Not _DateIsValid($Start) Or Not _DateIsValid($End) Then
        MsgBox(0, "Error", "The specified date is invalid.")
        Return ""
    Else
        $Difference = _DateDiff('s', $Start, $End)
        $rand = Random(0, $Difference, 1)
        Return _DateAdd('s', $rand, $Start)
    EndIf
EndFunc

I'm doing something wrong, right? :)

♡♡♡

.

eMyvnE

Posted

Now This is a Rabdom Date Function...

ConsoleWrite(RandomDate() & @CRLF)

ConsoleWrite(RandomDate("Male") & @CRLF)

ConsoleWrite(RandomDate("Female") & @CRLF)

Func RandomDate($iSex = "Male")
    $sList = "Cindy,Debbie,Laticia,Wilma,Sorry,Try Again!"
    If $iSex = "Female" Then $sList = "Brett,George,Ron,Jon,Sorry,Try Again!"
    $sSplit = StringSplit($sList, ",")
    Return $sSplit[(Random(1, $sSplit[0], 1))]
EndFunc   ;==>RandomDate

8)

NEWHeader1.png

Posted

Now This is a Rabdom Date Function...

ConsoleWrite(RandomDate() & @CRLF)

ConsoleWrite(RandomDate("Male") & @CRLF)

ConsoleWrite(RandomDate("Female") & @CRLF)

Func RandomDate($iSex = "Male")
    $sList = "Cindy,Debbie,Laticia,Wilma,Sorry,Try Again!"
    If $iSex = "Female" Then $sList = "Brett,George,Ron,Jon,Sorry,Try Again!"
    $sSplit = StringSplit($sList, ",")
    Return $sSplit[(Random(1, $sSplit[0], 1))]
EndFunc   ;==>RandomDate

8)

Hmmmmmmmmmm.

Are you sure you have this part right?

$sList = "Cindy,Debbie,Laticia,Wilma,Sorry,Try Again!"
    If $iSex = "Female" Then $sList = "Brett,George,Ron,Jon,Sorry,Try Again!"

Not sure if I should raise an objection or not.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

Hmmmmmmmmmm.

Are you sure you have this part right?

$sList = "Cindy,Debbie,Laticia,Wilma,Sorry,Try Again!"
     If $iSex = "Female" Then $sList = "Brett,George,Ron,Jon,Sorry,Try Again!"

Not sure if I should raise an objection or not.

That's Great, Your the winner, Someone who really read the code!!! :)

8)

Edited by Valuater

NEWHeader1.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...