Jump to content
Sign in to follow this  
greggklein

random numbers

Recommended Posts

greggklein

How can I have autoit pick 10 different random numbers between 1-400 and make sure they are all different.

Thanks

Share this post


Link to post
Share on other sites
Achilles

#include<Array.au3>
Dim $array[10]

For $i = 0 to 9 
    Do 
        $temp = Random(1, 400, 1) 
    Until _ArraySearch($array, $temp) = -1 
    $array[$i] = $temp 
Next 

_ArrayDisplay($array)
Try to understand exactly what each statement of this code is doing. If you don't, ask.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
everseeker

#include<Array.au3>
Dim $array[10]

For $i = 0 to 9 
    Do 
        $temp = Random(1, 400, 1) 
    Until _ArraySearch($array, $temp) = -1 
    $array[$i] = $temp 
Next 

_ArrayDisplay($array)
Try to understand exactly what each statement of this code is doing. If you don't, ask.
took a sec to get it.... Nice!

Everseeker

Share this post


Link to post
Share on other sites
d4rk

easiest way :D

random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1)

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
greggklein

#include<Array.au3>
Dim $array[10]

For $i = 0 to 9 
    Do 
        $temp = Random(1, 400, 1) 
    Until _ArraySearch($array, $temp) = -1 
    $array[$i] = $temp 
Next 

_ArrayDisplay($array)
Try to understand exactly what each statement of this code is doing. If you don't, ask.

THANK YOU

I DO UNDERSTAND IT ALL! :D

Share this post


Link to post
Share on other sites
greggklein

easiest way :D

random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1)

NOT SURE THAT'S EASIER, BUT THANKS

Share this post


Link to post
Share on other sites
Achilles

easiest way :D

random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1) & random(1,400,1)
That kind of ignores his condition that none of the numbers repeat.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
d4rk

That kind of ignores his condition that none of the numbers repeat.

what do you mean ?

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
Achilles

what do you mean ?

He wanted:

10 different random numbers between 1-400 and make sure they are all different.

You're code won't necessarily generate 10 unique numbers, numbers could repeat. My code makes sure that no numbers repeat.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
d4rk

what's the differece ? you also use random in your code, and what make sure that your code won't give out a repeat number ?


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites
Achilles

what's the differece ? you also use random in your code, and what make sure that your code won't give out a repeat number ?

The difference is that I gave what he wanted while you ignored half of his requisites for the the code he wanted. See this part:

Do
        $temp = Random(1, 400, 1)
    Until _ArraySearch($array, $temp) = -1
That loops until the number to be added isn't in the array; consequently 10 unique numbers are generated.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
d4rk

The difference is that I gave what he wanted while you ignored half of his requisites for the the code he wanted. See this part:

Do
        $temp = Random(1, 400, 1)
    Until _ArraySearch($array, $temp) = -1
That loops until the number to be added isn't in the array; consequently 10 unique numbers are generated.
ok, got it

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

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  

×