Jump to content
Sign in to follow this  
slayerz

Random No: Help pliz!

Recommended Posts

slayerz

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]

Share this post


Link to post
Share on other sites
ChrisL

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
slayerz

Or, perhaps, isn't never not same...?

:lmao:

Thank you so much everyone!!:whistle: I'm really appreciate your time for replying my probs!

Once again, thanks


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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.