Created
June 22, 2015 06:23
-
-
Save aki-lua87/6d93e412afedcbf3a349 to your computer and use it in GitHub Desktop.
シャッフル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shuffle_test; | |
public class deck | |
{ | |
//デッキ枚数 | |
int max = 10; | |
//カードデータ | |
int[] num = new int[max]; | |
//カードID | |
int[] id = new int[max]; | |
//データセット | |
public void init() | |
{ | |
for(int i = 0;i<max;i++) | |
{ | |
num[i] = i+11; | |
id[i] = i; | |
} | |
} | |
//シャッフル | |
public void SHUFFLE(int a,int b) | |
{ | |
int temp = id[a]; | |
id[a] = id[b]; | |
id[b] = temp; | |
} | |
//カード↓から表示 | |
public void printNum() | |
{ | |
for(int i = 0;i<max;i++) | |
{ | |
System.out.println(num[id[i]]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shuffle_test; | |
import java.util.Random; | |
public class mein { | |
public static void main(String[] args) | |
{ | |
//初期化 | |
test Test = new test(); | |
Test.init(); //コンストラクタでよかった | |
System.out.println("set ok!"); | |
//シャッフル前表示 | |
System.out.println("before num ->"); | |
Test.printNum(); | |
//ランダム作るマン | |
Random random = new Random(); | |
//枚数×10回シャッフル | |
for(int i = 0;i<Test.max*10;i++) | |
{ | |
Test.SHUFFLE(random.nextInt(10),random.nextInt(10)); | |
} | |
//シャッフル後表示 | |
System.out.println("after num ->"); | |
Test.printNum(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment