Jump to content

Random No: Help pliz!


Recommended Posts

Hello everyone... I'd made script that will generate random no.

Random(1,15,1)

The prob is, I dun want it to generate same no. twice!

Does anyone know how to exclude the picked no. so that it's not same no.?

or, does anyone have an idea how to make a condition statement to generate other no. if the no. has been selected?

AUTOIT[sup] I'm lovin' it![/sup]

Link to comment
Share on other sites

This works for whole numbers

include <array.au3>
$start = 1
$end = 15
$possibilities = ($end - $start) + 1
Local $storageArray[1]

While 1
    $randomNumber = Random($start,$End,1)
    
    If _ArraySearch($storageArray,$randomNumber) = -1 then 
        _ArrayAdd($storageArray,$randomNumber)
        ConsoleWrite($randomNumber & @crlf)
    ;Msgbox(0,"",$randomNumber)
    EndIf
    
    If Ubound($storageArray) -1 = $possibilities then ExitLoop
Wend
Link to comment
Share on other sites

This for generating two numbers (never not same):

$n1 = Random(1,15,1)
While 1
    $n2 = Random(1,15,1)
    If $n2 <> $n1 Then ExitLoop
WEnd
    
ConsoleWrite($n1 & @CRLF)   
ConsoleWrite($n2 & @CRLF)
Or, perhaps, isn't never not same...?

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...