shuffle algorithm - Commited into Github

AnnieRuru

~~Cute~Cute~Scripter~~
Messages
1,677
Points
0
Location
your next door ~
Discord
AnnieRuru#1609
Github
AnnieRuru
Emulator
Client Version
2019-05-30aRagexeRE
I really need a topic for this shuffle algorithm or I have to keep press the search button non-stop

what is Shuffle Algorithm ?

- it generate a set of numbers in random order that the numbers are not repeated

Wiki -> http://en.wikipedia.org/wiki/Fisher–Yates_shuffle

This script is no longer necessary,

use the one inside Global Function

Commit Link

Credit to @Haru

Pull #872

OUTDATED

Credit to @KeyWorld

http://www.eathena.ws/board/index.php?s=&showtopic=269819&view=findpost&p=1477362

Download:

http://upaste.me/fdc81111611fde9d2

.

.

.

PS: I want to click the Select Code button

Code:
//	callfunc "shuffle", <start index>, <last index>, <output array>, <count>;function	script	shuffle__	{	.@static = getarg(0);	.@range = getarg(1) +1 - .@static;	.@count = getarg(3, 0);	if ( .@range <= 0 )		return 0;	if ( !.@count || .@count > .@range )		.@count = .@range;	while ( .@i < .@count ) {		.@r = .@save = rand( .@i, .@range -1 ) ;		if ( !.@tmp1[.@i] ) {			.@r = .@tmp1[.@r] ? .@tmp2[.@r] : .@r;			.@tmp2[.@i] = .@r;			.@tmp2[.@save] = .@i;			.@tmp1[.@save] = 1;			set getelementofarray( getarg(2), .@i ), .@r + .@static;			if ( .@save < .@count )				set getelementofarray( getarg(2), .@save ), .@i + .@static;		}		.@i++;	}	return .@count;}
tested with
Code:
prontera,156,184,5	script	kjdshfksfjh	100,{//	input .@min, -1000000000, 1000000000;//	input .@[member="Max"], -1000000000, 1000000000;	.@min = 1;	.@[member="Max"] = 5;	callfunc "shuffle__", .@min, .@[member="Max"], .@output$, 100;	dispbottom implode( .@output$, "," );}
 
Last edited by a moderator:
I should've commented the sample script lol

algorithm script are only functions that doesn't work on its own

usually need to accompany with other scripts to work

yes, it only generate a set of random numbers that the numbers are not repeated

ok I need to tell what is a shuffle algorithm ...

 
Wow, that s nice.

Could be the base of lots of luck-based miini games/events and such...

Great job Keyworld / Annie

 
Wow, that s nice.

Could be the base of lots of luck-based miini games/events and such...

Great job Keyworld / Annie
I really want a lottery based script but never found a good one
default_tongue.png
maybe now it is time to someone to release it!

 
@Adam

I actually used it quite intensively in rathena forum

just search "rand__" over there and you'll get more than 10 results

I purposely change the name into "shuffle__" to differentiate rathena users and hercules users

(as we have unlimited array index, they don't have yet)

@evilpuncker

I thought lottery script is just draw a card in an array ?

set .@r, .array[ rand( getarraysize( .array ) ) ];its not like needed to shuffle the whole deckhttp://www.fredosaurus.com/notes-cpp/misc/random-shuffle.html

 
can work with mysql?
if you want to randomize the query, use ORDER BY RAND()
Code:
select * from `char` order by rand() limit 10;
nothing to do with this topic, though
 
Back
Top