Skip to content

Commit

Permalink
Add -seed support
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Sep 22, 2015
1 parent 29c904e commit 9572f49
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Empty file.
1 change: 1 addition & 0 deletions nbproject/configs/Random_with_fixed_seed.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$label=Random with fixed seed
6 changes: 5 additions & 1 deletion src/Simulateur.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public Simulateur(String[] args) throws ArgumentsException, Exception {

if (messageAleatoire) {
System.out.println("Mode aléatoire : "+nbBitsMess);
source = new SourceAleatoire(nbBitsMess);
if(aleatoireAvecGerme){
source = new SourceAleatoire(nbBitsMess,seed);
}else{
source = new SourceAleatoire(nbBitsMess);
}
System.out.println("Mode aléatoire fini");
} else {
System.out.println("Mode non aléatoire : "+messageString);
Expand Down
24 changes: 17 additions & 7 deletions src/sources/SourceAleatoire.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package sources;

import information.Information;
import java.util.Random;

public class SourceAleatoire extends Source<Boolean> {
public SourceAleatoire(int nbBits) {
super();
this.informationGeneree = new Information<Boolean>();
for(int i=0; i<nbBits; i++){
this.informationGeneree.add(Math.random()<0.5);
}
}

public SourceAleatoire(int nbBits) {
super();
this.informationGeneree = new Information<Boolean>();
for (int i = 0; i < nbBits; i++) {
this.informationGeneree.add(Math.random() < 0.5);
}
}
public SourceAleatoire(int nbBits,int seed) {
super();
this.informationGeneree = new Information<Boolean>();
Random generator = new Random(seed);
for (int i = 0; i < nbBits; i++) {
this.informationGeneree.add(generator.nextDouble() < 0.5);
}
}
}

0 comments on commit 9572f49

Please sign in to comment.