Jump to content
Sign in to follow this  
AnnieRuru

shuffle algorithm - Commited into Github

Recommended Posts

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

//	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
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$, "," );}

 

Edited by AnnieRuru

Share this post


Link to post
Share on other sites

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 ...

Share this post


Link to post
Share on other sites

Wow, that s nice.

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

Great job Keyworld / Annie

Share this post


Link to post
Share on other sites

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 :P maybe now it is time to someone to release it!

Share this post


Link to post
Share on other sites

@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 deck

http://www.fredosaurus.com/notes-cpp/misc/random-shuffle.html

Share this post


Link to post
Share on other sites

can work with mysql?

if you want to randomize the query, use ORDER BY RAND()
select * from `char` order by rand() limit 10;
nothing to do with this topic, though

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.