Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7451121
Random.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
Random.java
View Options
package
org.softwareheritage.graph.benchmark.utils
;
import
java.util.PrimitiveIterator
;
import
org.softwareheritage.graph.Graph
;
import
org.softwareheritage.graph.Node
;
/**
* Random related utility class.
*
* @author The Software Heritage developers
*/
public
class
Random
{
/** Internal pseudorandom generator */
java
.
util
.
Random
random
;
/**
* Constructor.
*/
public
Random
()
{
this
.
random
=
new
java
.
util
.
Random
();
}
/**
* Constructor.
*
* @param seed random generator seed
*/
public
Random
(
long
seed
)
{
this
.
random
=
new
java
.
util
.
Random
(
seed
);
}
/**
* Generates random node ids.
*
* @param graph graph used to pick node ids
* @param nbNodes number of node ids to generate
* @return an array of random node ids
*/
public
long
[]
generateNodeIds
(
Graph
graph
,
int
nbNodes
)
{
return
random
.
longs
(
nbNodes
,
0
,
graph
.
numNodes
()).
toArray
();
}
/**
* Generates random node ids with a specific type.
*
* @param graph graph used to pick node ids
* @param nbNodes number of node ids to generate
* @param expectedType specific node type to pick
* @return an array of random node ids
*/
public
long
[]
generateNodeIdsOfType
(
Graph
graph
,
int
nbNodes
,
Node
.
Type
expectedType
)
{
PrimitiveIterator
.
OfLong
nodes
=
random
.
longs
(
0
,
graph
.
numNodes
()).
iterator
();
long
[]
nodeIds
=
new
long
[
nbNodes
];
long
nextId
;
for
(
int
i
=
0
;
i
<
nbNodes
;
i
++)
{
do
{
nextId
=
nodes
.
nextLong
();
}
while
(
graph
.
getNodeType
(
nextId
)
!=
expectedType
);
nodeIds
[
i
]
=
nextId
;
}
return
nodeIds
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Thu, Apr 17, 9:47 AM (4 d, 18 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3278347
Attached To
rDGRPH Compressed graph representation
Event Timeline
Log In to Comment