Jump to content

how to use random..


zutto
 Share

Recommended Posts

yeah :D

i know howto use with letters & numbers..

but i have no idea howto use with - and +.. need for my script to chose randomly between + and - :S

any ideas?

$sSign = "+"

If Random(0,1,1) Then $sSign = "-"

;)

Or, since we're having a geek fest with this:

$sSign = Chr(43 + (2 * Random(0,1,1)))

;)

Or the SmOke_N way:

$sSign = StringRegExpReplace("+-", "(\+)(\-)", "\" & Random(1,2,1))

:lmao:

Edit: Rats! He already posted it!

Edited by PsaltyDS
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

  • Moderators

yeah ;)

i know howto use with letters & numbers..

but i have no idea howto use with - and +.. need for my script to chose randomly between + and - :S

any ideas?

Local $a_add_sub[2] = ["-", "+"]
MsgBox(0, "", Execute( 8 & $a_add_sub[Random(0, 1, 1)] & 10))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

$sSign = Chr(43 + (2 * Random(0,1,1)))

;)

There must be more options than these .. :D

Someone say geek?

MsgBox(0, 0, StringRegExpReplace("-+", "(.)(.)", "\" & Random(1, 2, 1)))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I don't like casting the sign to character.

If you have a given number and you want its sign to randomly change then...

$num = 666
If Random(0,1,1) Then $num *= -1
ConsoleWrite($num & @CRLF)
I used this method with bcx.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

No, we are recovering geeks.

;)

I don't go to meetings...

Edit:

And I never made it past step 1 anyway!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

I still prefer the "normal" approach ;)

Still don't like to regex thingies when relaxing after a days work.

StringMid("-+",Random(1,2,1),1)

Edit: i see I am not the only one that likes the sweet and simple approach :D

Edited by Jos

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

  • Moderators

I still prefer the "normal" approach :D

Still don't like to regex thingies when relaxing after a days work.

StringMid("-+",Random(1,2,1),1)

Edit: i see I am not the only one that likes the sweet and simple approach ;)

Wouldn't this have been simpler with StringMid you regex nerd?

Why use 10 string functions when you only need 1? I may be the nerd, but at least I'm consistent ;)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

When you say 10, that is binary right?

;)

Missing a few chars there for binary I think ...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

@SmoKE - You are at a meeting! what do you think this forum is? ;)

Hell I'm the president of my chapter then.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Nay, I say you should find the length of the memory space for the running application, then read a random location in the application. If the value is < 128, then it's negative, if >= 128, positive.

Sorry, I don't have a code example because I just got my hand slammed in a truck door and I can't type really well yet.

Good Idea!

I'll add that to this after I eat lunch ;)

$random = Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + 5 + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) / 2 + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + 5 + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) / 2 + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), Random(Random(Random(Random(0,1,1), 2, 1), _
Random(0,1,1), 1) + 1, 2, 1), 1) + Random(Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), _
Random(Random(Random(Random(0,1,1), 2, 1), Random(0,1,1), 1) + 1, 2, 1), 1)
If $random > 20 Then 
    $random = StringMid("-+",Random(1,2,1),1) & 1
ElseIf $random > 10 Then
    $random = 0
EndIf
MsgBox(0, "", $random)
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...