Random Number Generator Topic is solved

Ask gaming related questions (AHK v1.1 and older)
UnderwearDood
Posts: 3
Joined: 06 Mar 2018, 23:36
Contact:

Random Number Generator

24 Mar 2018, 15:02

I'm a beginner and i made a script for spamming. All it does is spam "I'm leveling up!!" in chat. But i want it to paste a few random quotes out of 3 or more instead of just one like "hehe xd" and "Would you like a free sample?". Basically i want a script that spams 3 random quotes. Thx for the help

Code: Select all

^NumPad1::

$pause := 0

Loop,

{

	Clipboard = I'm leveling up!! 
	sleep 450
	send ^v
	sleep 500
	send {Enter}
	Clipboard =
	if ($pause)
	{
		return
	}
}

End:: $pause := 1
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Random Number Generator  Topic is solved

24 Mar 2018, 19:43

Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

Phrases := []
Phrases.Push({weight: 7, str: "Would you like a free sample?"})
Phrases.Push({weight: 5, str: "Random Number Generator"})
Phrases.Push({weight: 3, str: "To be or not to be?"})

Loop
    MsgBox, % PickOne(Phrases).str

Esc:: ExitApp



;-------------------------------------------------------------------------------
PickOne(List) { ; every item in List has weight property
;-------------------------------------------------------------------------------
    Loop, % List.Length()
        TotalWeight += List[A_Index].weight
    Random, r, 0.0, TotalWeight
    While (r > 0)
        r -= List[i := A_Index].weight
    Return, List[i]
}
I hope that helps.
UnderwearDood
Posts: 3
Joined: 06 Mar 2018, 23:36
Contact:

Re: Random Number Generator

25 Mar 2018, 00:04

Thank you so much!!!! this was what i wanted. It took a little experimenting to add some stuff i wanted, but its working the way i want it to. This is great!!

Another Request: can you explain to me the bottom part and what is does?

Code: Select all

    Loop, % List.Length()
        TotalWeight += List[A_Index].weight
    Random, r, 0.0, TotalWeight
    While (r > 0)
        r -= List[i := A_Index].weight
    Return, List[i]
}
Anyway thanks for the help and quick reply :D
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Random Number Generator

25 Mar 2018, 06:24

There is a video I got it from: Watch and I'm happy to explain based on the video, should you need to ask more questions.
https://www.youtube.com/watch?v=ETphJAS ... HV&index=8
It is a part of about 10 videos about genetic algorithms, where it all got done by the book (which the guy wrote himself).
In practice, the final alg is much faster, needs LOADS less memory, and can produce a result on every call. (compared to the first alg from the book, [please watch to see what it's about ?!)

PS: I will be glad to write about code all day long, but the video will probably give you a better start.
UnderwearDood
Posts: 3
Joined: 06 Mar 2018, 23:36
Contact:

Re: Random Number Generator

25 Mar 2018, 13:07

Thanks, the video was a little bit too advanced for me :? i just got into scripts and coding, but this helped me understand a it little bit more. Thanks for all the help :bravo:

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 32 guests