gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under
the git version control system
1 import java
.math
.BigInteger
;
2 import java
.util
.Random
;
3 import java
.util
.concurrent
.atomic
.AtomicInteger
;
5 import org
.svetovid
.io
.SvetovidReader
;
6 import org
.svetovid
.io
.SvetovidWriter
;
8 public class StabloIORandom
implements StabloIO
{
14 public StabloIORandom() {
15 this(System
.currentTimeMillis());
18 public StabloIORandom(long seed
) {
22 public StabloIORandom(long seed
, int length
, int depth
) {
28 public long getSeed() {
32 public void setSeed(long seed
) {
36 public int getLength() {
40 public void setLength(int length
) {
44 public int getDepth() {
48 public void setDepth(int depth
) {
53 public Stablo
readStablo(SvetovidReader in
) {
54 Random random
= new Random(seed
);
55 AtomicInteger sequence
= new AtomicInteger();
56 Stablo stablo
= readStablo(random
, sequence
, length
, depth
);
60 private Stablo
readStablo(Random random
, AtomicInteger sequence
, int length
, int depth
) {
64 int id
= sequence
.addAndGet(1 + random
.nextInt(9));
65 String vrednost
= new BigInteger(length
, random
).toString(36);
66 Stablo desni
= readStablo(random
, sequence
, length
+ random
.nextInt(5), depth
- random
.nextInt(5));
67 Stablo levi
= readStablo(random
, sequence
, length
+ random
.nextInt(5), depth
- random
.nextInt(5));
68 return new Stablo(id
, vrednost
, levi
, desni
);
72 public void printStablo(SvetovidWriter out
, Stablo stablo
) {
73 throw new UnsupportedOperationException();
Svarog.pmf.uns.ac.rs/gitweb
maintanance
Doni Pracner