Skip to content

Commit

Permalink
added math function 'rand-bigint'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 31, 2024
1 parent ca38303 commit 160b872
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- thread type support to the function `thread` to allow spawning daemon or user
threads
- support for tracing exceptions in `trace/trace-var`
- math function `rand-bigint`



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public DocSection section() {
all.addSection(random);
random.addItem(diBuilder.getDocItem("rand-long"));
random.addItem(diBuilder.getDocItem("rand-double"));
random.addItem(diBuilder.getDocItem("rand-bigint"));
random.addItem(diBuilder.getDocItem("rand-gaussian"));

final DocSection trigonometry = new DocSection("Trigonometry", "math.trigonometry");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,7 @@ else if (q == 1.0D) {
"(rand-long 100)")
.seeAlso(
"rand-double",
"rand-bigint",
"rand-gaussian",
"bytebuf-allocate-random")
.build()
Expand Down Expand Up @@ -1581,8 +1582,9 @@ public VncVal apply(final VncList args) {
"(rand-double 100.0)")
.seeAlso(
"rand-long",
"rand-bigint",
"rand-gaussian",
"bytebuf-allocate-random")
"bytebuf-allocate-random")
.build()
) {
@Override
Expand Down Expand Up @@ -1627,6 +1629,7 @@ public VncVal apply(final VncList args) {
.seeAlso(
"rand-long",
"rand-double",
"rand-bigint",
"bytebuf-allocate-random")
.build()
) {
Expand All @@ -1647,6 +1650,42 @@ public VncVal apply(final VncList args) {
private static final long serialVersionUID = -1848883965231344442L;
};

public static VncFunction rand_bigint =
new VncFunction(
"rand-bigint",
VncFunction
.meta()
.arglists(
"(rand-bigint bits)")
.doc(
"Constructs a randomly generated BigInteger, uniformly distributed " +
"over the range 0 to (2^N - 1), inclusive.")
.examples(
"(rand-bigint 256)")
.seeAlso(
"rand-long",
"rand-double",
"rand-gaussian",
"bytebuf-allocate-random")
.build()
) {
@Override
public VncVal apply(final VncList args) {
ArityExceptions.assertArity(this, args, 1);

final long bits = Coerce.toVncLong(args.first()).getValue();

if (bits < 2 || bits > 65536) {
throw new VncException(
"Function 'rand-bigint': bits must be in the range [2..65536]");
}

return new VncBigInteger(new BigInteger((int)bits, random));
}

private static final long serialVersionUID = -1848883965231344442L;
};

public static VncFunction zero_Q =
new VncFunction(
"zero?",
Expand Down Expand Up @@ -2263,6 +2302,7 @@ private static VncVal median(final VncList sortedData) {

.add(rand_long)
.add(rand_double)
.add(rand_bigint)
.add(rand_gaussian)

.add(range)
Expand Down

0 comments on commit 160b872

Please sign in to comment.