Skip to content

Commit

Permalink
Change to semantics of RandomPicker's constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Mar 18, 2020
1 parent 56aacf2 commit ac41b7b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*.swp
*.bak
*.old

*.zip
# MacOS !#@$ files
.DS_Store

Expand Down
39 changes: 39 additions & 0 deletions Source/Core/src/ca/uqac/lif/synthia/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Synthia, a data structure generator
Copyright (C) 2019-2020 Laboratoire d'informatique formelle
Université du Québec à Chicoutimi, Canada
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ca.uqac.lif.synthia;

/**
* Dummy main file. This file, when run, only displays a message
* on the console.
*/
public class Main
{
private Main()
{
super();
throw new UnsupportedOperationException("This class cannot be instantiated");
}

public static void main(String[] args)
{
System.out.println("Synthia - A data structure generator");
System.out.println("(C) 2019-2020 Laboratoire d'informatique formelle");
System.out.println("Université du Québec à Chicoutimi, Canada");
}
}
8 changes: 7 additions & 1 deletion Source/Core/src/ca/uqac/lif/synthia/random/RandomPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
*/
public abstract class RandomPicker<T> implements Picker<T>, Seedable
{
/**
* A random number generator used to set the seed when none is
* specified
*/
protected static final transient Random s_random = new Random();

/*@ non_null @*/ protected transient Random m_random;

protected int m_seed;
Expand All @@ -49,7 +55,7 @@ public RandomPicker(int seed)

public RandomPicker()
{
this(0);
this(s_random.nextInt());
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/src/ca/uqac/lif/synthia/replay/Playback.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
* System.out.println(p.pick()); // 2
* ...</pre>
* Optionally, the picker can be told to start at a different element than the
* first one.
* first one. By default, the picker keeps outputting the last value of the
* sequence if more values are requested and the <tt>loop</tt> parameter is
* set to false.
* @param <T> The type of objects to return
*/
public class Playback<T> implements Picker<T>
Expand Down Expand Up @@ -111,7 +113,7 @@ public T pick()
{
if (m_index >= m_values.length && !m_loop)
{
return null;
return m_values[m_values.length - 1];
}
T f = m_values[m_index];
m_index++;
Expand Down
5 changes: 4 additions & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<author>Sylvain Hallé</author>

<!-- The project's main class -->
<mainclass>ca.uqac.lif.ptlogger2.Main</mainclass>
<mainclass>ca.uqac.lif.synthia.Main</mainclass>

<!-- The project's version number -->
<version>0.1.1</version>

<test>
<!-- The filename pattern to recognize test files -->
Expand Down

0 comments on commit ac41b7b

Please sign in to comment.