Jump to content

Random number


Erik.
 Share

Recommended Posts

Hi,

I have found that you can generate a number between

300 and 3000 whit the function random:

local $random = random(300, 3000, 1)

The random number will be writen to an ini file as key.

how to let the program first check if the number already exists and if it exists it must make a new random number so you never have the same...

Could someone help me whit that?

Gr Erik

Edited by Erik.

I little problem, hard to find and fix

Link to comment
Share on other sites

You could use a while loop and then in the while loop have it check and if it is the same continue the loop, if it isn't then exit the loop. Give me a couple min to whip something up for you.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Hi,

I have found that you can generate a number between

300 and 3000 whit the function random:

local $random = random(300, 3000, 1)

The random number will be writen to an ini file as key.

how to let the program first check if the number already exists and if it exists it must make a new random number so you never have the same...

Could someone help me whit that?

Gr Erik

Do
    $random = random(300, 3000, 1)
Until IniRead("inifile.ini","Section",$random,0)<>0

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi,

Thanks for your posts.

@ JdeB

The ini file has many of that random numbers..

When it has found a number whit the same as into the ini file it needs to make a new one that is not into the ini file...

Will wait for you script

Thanks

Gr Erik

Edited by Erik.

I little problem, hard to find and fix

Link to comment
Share on other sites

  • Developers

Hi,

Thanks for your posts.

@ JdeB

The ini file has many of that random numbers..

When it has found a number whit the same as into the ini file it needs to make a new one that is not into the ini file...

Will wait for you script

Thanks

Gr Erik

Nah ... don't wait for it ... I have given you an approach to follow ... so its up to you to build on it .... ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Here is something i made that should do the job.

Dim $i_INIValue = IniRead("inifile.ini","Section","RandomNumbKey",-1)
If $i_INIValue = -1 Then
    Msgbox(0,"Error","Could not read the INIfile.")
    Exit
Endif

Dim $i_RandomNum
While 1
    $i_RandomNum = Random(300,3000,1)
    
    IF $i_RandomNum <> $i_INIValue Then ExitLoop
    
Wend

Msgbox(0,"Done!",'The number in the ini file is ' & $i_INIValue & ' and the number that was generated randomly is ' & $i_RandomNum )

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Here is something i made that should do the job.

Dim $i_INIValue = IniRead("inifile.ini","Section","RandomNumbKey",-1)
If $i_INIValue = -1 Then
    Msgbox(0,"Error","Could not read the INIfile.")
    Exit
Endif

Dim $i_RandomNum
While 1
    $i_RandomNum = Random(300,3000,1)
    
    IF $i_RandomNum <> $i_INIValue Then ExitLoop
    
Wend

Msgbox(0,"Done!",'The number in the ini file is ' & $i_INIValue & ' and the number that was generated randomly is ' & $i_RandomNum )
This assumes the random number is the value of the key ... not the key itself ... ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok, i didn't understand, try this:

Dim $i_INIValue = IniRead("inifile.ini","Section","RandomNumbKey",-1)
Dim $a_ReadKeys = IniReadSection ("inifile.ini", "Section" )
If $i_INIValue = -1 Then
    Msgbox(0,"Error","Could not read the INIfile.")
    Exit
Endif

Dim $i_intcount
Dim $i_RandomNum
Dim $b_success
While 1
    $i_RandomNum = Random(300,3000,1)
    $b_success = True
    For $i_intcount = 1 To $a_ReadKeys[0][0]
        IF $i_RandomNum = $a_ReadKeys[$i_intcount][1] or $i_RandomNum = $a_ReadKeys[$i_intcount][0]  Then 
            $b_success = False
            ExitLoop
        Endif
    Next
    If $b_success = True Then Exitloop
Wend

Msgbox(0,"Done!",'The number in the ini file is ' & $i_INIValue & ' and the number that was genereated randomly is ' & $i_RandomNum )

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Developers

Still think my version is a bit less complex ... but "There are many roads leading to Rome ..." ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi,

Yes i know i have send you a message....

i only need some lines not the whole script because i want to learn of it and i want to try to edit it bij mij self...

When i don't know how to make some thing i ask for a few lines and edit it so i can use it into my script...

Hope you understand it

I little problem, hard to find and fix

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...