File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 35
35
import java .io .InputStream ;
36
36
import java .io .InputStreamReader ;
37
37
import java .io .OutputStream ;
38
+ import java .math .BigInteger ;
38
39
import java .nio .ByteBuffer ;
39
40
import java .nio .channels .NonWritableChannelException ;
40
41
import java .nio .channels .SeekableByteChannel ;
50
51
import java .util .List ;
51
52
import java .util .Map ;
52
53
import java .util .Map .Entry ;
54
+ import java .util .Random ;
53
55
import java .util .Set ;
54
56
55
57
import com .oracle .graal .python .builtins .Builtin ;
@@ -894,4 +896,18 @@ int system(String cmd) {
894
896
}
895
897
}
896
898
}
899
+
900
+ @ Builtin (name = "urandom" , fixedNumOfArguments = 1 )
901
+ @ GenerateNodeFactory
902
+ abstract static class URandomNode extends PythonBuiltinNode {
903
+ @ Specialization
904
+ @ TruffleBoundary
905
+ PBytes urandom (int size ) {
906
+ // size is in bytes
907
+ BigInteger bigInteger = new BigInteger (size * 8 , new Random ());
908
+ // sign may introduce an extra byte
909
+ byte [] range = Arrays .copyOfRange (bigInteger .toByteArray (), 0 , size );
910
+ return factory ().createBytes (range );
911
+ }
912
+ }
897
913
}
You can’t perform that action at this time.
0 commit comments