# Random number

## 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

##### 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

##### Share on other sites

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)

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Hi,

@ 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

##### Share on other sites

Hi,

@ 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 ....

Live for the present,
Dream of the future,
Learn from the past.

##### 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
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

##### 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
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 ...

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Ok, i didn't understand, try this:

```Dim \$i_INIValue = IniRead("inifile.ini","Section","RandomNumbKey",-1)
If \$i_INIValue = -1 Then
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]
\$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

##### Share on other sites

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

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Erik i already had put a double key prevent in yours , lol just didnt let me respond send me ur complete code cuz i delted it

Edited by Thatsgreat2345

##### 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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...