Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Convert this C# block to Rust, preserving its control flow and logic.
using System; using System.Collections.Generic; using System.Linq; using System.Threading; class Program { static void ThreadStart(object item) { Thread.Sleep(1000 * (int)item); Console.WriteLine(item); } static void SleepSort(IEnumerable<int> items) { foreach (var item in ...
use std::thread; fn sleepsort<I: Iterator<Item=u32>>(nums: I) { let threads: Vec<_> = nums.map(|n| thread::spawn(move || { thread::sleep_ms(n); println!("{}", n); })).collect(); for t in threads { t.join(); } } fn main() { sleepsort(std::env::args().skip(1).map(|s| s.parse(...
Convert this Java block to Rust, preserving its control flow and logic.
import java.util.concurrent.CountDownLatch; public class SleepSort { public static void sleepSortAndPrint(int[] nums) { final CountDownLatch doneSignal = new CountDownLatch(nums.length); for (final int num : nums) { new Thread(new Runnable() { public void run() { doneSignal.countDown(); try { ...
use std::thread; fn sleepsort<I: Iterator<Item=u32>>(nums: I) { let threads: Vec<_> = nums.map(|n| thread::spawn(move || { thread::sleep_ms(n); println!("{}", n); })).collect(); for t in threads { t.join(); } } fn main() { sleepsort(std::env::args().skip(1).map(|s| s.parse(...
Write the same algorithm in Rust as shown in this Go implementation.
package main import ( "fmt" "log" "os" "strconv" "time" ) func main() { out := make(chan uint64) for _, a := range os.Args[1:] { i, err := strconv.ParseUint(a, 10, 64) if err != nil { log.Fatal(err) } go func(n uint64) { time.Sleep(time.Duration(n) * time.Millisecond) out <- n }(i) } for _...
use std::thread; fn sleepsort<I: Iterator<Item=u32>>(nums: I) { let threads: Vec<_> = nums.map(|n| thread::spawn(move || { thread::sleep_ms(n); println!("{}", n); })).collect(); for t in threads { t.join(); } } fn main() { sleepsort(std::env::args().skip(1).map(|s| s.parse(...
Produce a language-to-language conversion: from Rust to Python, same semantics.
use std::thread; fn sleepsort<I: Iterator<Item=u32>>(nums: I) { let threads: Vec<_> = nums.map(|n| thread::spawn(move || { thread::sleep_ms(n); println!("{}", n); })).collect(); for t in threads { t.join(); } } fn main() { sleepsort(std::env::args().skip(1).map(|s| s.parse(...
from time import sleep from threading import Timer def sleepsort(values): sleepsort.result = [] def add1(x): sleepsort.result.append(x) mx = values[0] for v in values: if mx < v: mx = v Timer(v, add1, [v]).start() sleep(mx+1) return sleepsort.result if __name__ == '__ma...
Port the provided Rust code into VB while preserving the original functionality.
use std::thread; fn sleepsort<I: Iterator<Item=u32>>(nums: I) { let threads: Vec<_> = nums.map(|n| thread::spawn(move || { thread::sleep_ms(n); println!("{}", n); })).collect(); for t in threads { t.join(); } } fn main() { sleepsort(std::env::args().skip(1).map(|s| s.parse(...
Imports System.Threading Module Module1 Sub SleepSort(items As IEnumerable(Of Integer)) For Each item In items Task.Factory.StartNew(Sub() Thread.Sleep(1000 * item) Console.WriteLine(item) ...
Convert the following code from Ada to C#, ensuring the logic remains intact.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Convert the following code from Ada to C#, ensuring the logic remains intact.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Generate an equivalent C version of this Ada code.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Maintain the same structure and functionality when rewriting this code in C.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Change the programming language of this snippet from Ada to C++ without modifying what it does.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Convert this Ada block to C++, preserving its control flow and logic.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Rewrite this program in Go while keeping its functionality equivalent to the Ada version.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Translate this program into Go but keep the logic exactly as in Ada.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Keep all operations the same but rewrite the snippet in Java.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Generate an equivalent Java version of this Ada code.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Translate this program into Python but keep the logic exactly as in Ada.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
import random rand = random.SystemRandom() rand.randint(1,10)
Transform the following Ada implementation into Python, maintaining the same output and logic.
with Ada.Streams.Stream_IO; with Ada.Text_IO; procedure Random is Number : Integer; Random_File : Ada.Streams.Stream_IO.File_Type; begin Ada.Streams.Stream_IO.Open (File => Random_File, Mode => Ada.Streams.Stream_IO.In_File, Name => "/dev/random"); ...
import random rand = random.SystemRandom() rand.randint(1,10)
Write the same algorithm in C as shown in this BBC_Basic implementation.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Generate an equivalent C version of this BBC_Basic code.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Produce a language-to-language conversion: from BBC_Basic to C#, same semantics.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Port the provided BBC_Basic code into C# while preserving the original functionality.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Convert this BBC_Basic snippet to C++ and keep its semantics consistent.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Rewrite the snippet below in C++ so it works the same as the original BBC_Basic code.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Write a version of this BBC_Basic function in Java with identical behavior.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Generate a Java translation of this BBC_Basic snippet without changing its computational steps.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Change the programming language of this snippet from BBC_Basic to Python without modifying what it does.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
import random rand = random.SystemRandom() rand.randint(1,10)
Produce a functionally identical Python code for the snippet given in BBC_Basic.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
import random rand = random.SystemRandom() rand.randint(1,10)
Keep all operations the same but rewrite the snippet in Go.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Convert the following code from BBC_Basic to Go, ensuring the logic remains intact.
SYS "SystemFunction036", ^random%, 4 PRINT ~random%
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Generate an equivalent C version of this Common_Lisp code.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Convert this Common_Lisp block to C, preserving its control flow and logic.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Produce a language-to-language conversion: from Common_Lisp to C#, same semantics.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Transform the following Common_Lisp implementation into C#, maintaining the same output and logic.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Generate a C++ translation of this Common_Lisp snippet without changing its computational steps.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Convert this Common_Lisp block to C++, preserving its control flow and logic.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Please provide an equivalent version of this Common_Lisp code in Java.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Maintain the same structure and functionality when rewriting this code in Java.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Ensure the translated Python code behaves exactly like the original Common_Lisp snippet.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
import random rand = random.SystemRandom() rand.randint(1,10)
Rewrite the snippet below in Python so it works the same as the original Common_Lisp code.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
import random rand = random.SystemRandom() rand.randint(1,10)
Change the following Common_Lisp code into Go without altering its purpose.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Convert this Common_Lisp block to Go, preserving its control flow and logic.
(defun random-int32 () (with-open-file (s "/dev/random" :element-type '(unsigned-byte 32)) (read-byte s)))
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Change the following D code into C without altering its purpose.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Write the same code in C as shown below in D.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Rewrite the snippet below in C# so it works the same as the original D code.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Keep all operations the same but rewrite the snippet in C#.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Keep all operations the same but rewrite the snippet in C++.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Convert this D snippet to C++ and keep its semantics consistent.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Preserve the algorithm and functionality while converting the code from D to Java.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Transform the following D implementation into Java, maintaining the same output and logic.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Rewrite this program in Python while keeping its functionality equivalent to the D version.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
import random rand = random.SystemRandom() rand.randint(1,10)
Can you help me rewrite this code in Python instead of D, keeping it the same logically?
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
import random rand = random.SystemRandom() rand.randint(1,10)
Port the provided D code into Go while preserving the original functionality.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Transform the following D implementation into Go, maintaining the same output and logic.
import std.stdio; import std.random; void main() { Mt19937 gen; gen.seed(unpredictableSeed); auto n = gen.front; writeln(n); }
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Convert the following code from Delphi to C, ensuring the logic remains intact.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Ensure the translated C code behaves exactly like the original Delphi snippet.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Please provide an equivalent version of this Delphi code in C#.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Produce a language-to-language conversion: from Delphi to C#, same semantics.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Translate this program into C++ but keep the logic exactly as in Delphi.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Translate the given Delphi code snippet into C++ without altering its behavior.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Produce a language-to-language conversion: from Delphi to Java, same semantics.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Convert this Delphi snippet to Java and keep its semantics consistent.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Maintain the same structure and functionality when rewriting this code in Python.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
import random rand = random.SystemRandom() rand.randint(1,10)
Rewrite the snippet below in Python so it works the same as the original Delphi code.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
import random rand = random.SystemRandom() rand.randint(1,10)
Convert this Delphi snippet to Go and keep its semantics consistent.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Translate this program into Go but keep the logic exactly as in Delphi.
program Random_number_generator; uses System.SysUtils, Winapi.WinCrypt; var hCryptProv: NativeUInt; i: Byte; UserName: PChar; function Random: UInt64; var pbData: array[0..7] of byte; i: integer; begin if not CryptGenRandom(hCryptProv, 8, @pbData[0]) then exit(0); Result := 0; for i := 0 to...
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Convert this Factor block to C, preserving its control flow and logic.
USE: random [ random-32 ] with-system-random .
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Preserve the algorithm and functionality while converting the code from Factor to C.
USE: random [ random-32 ] with-system-random .
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Keep all operations the same but rewrite the snippet in C#.
USE: random [ random-32 ] with-system-random .
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Write a version of this Factor function in C# with identical behavior.
USE: random [ random-32 ] with-system-random .
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Rewrite this program in C++ while keeping its functionality equivalent to the Factor version.
USE: random [ random-32 ] with-system-random .
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Ensure the translated C++ code behaves exactly like the original Factor snippet.
USE: random [ random-32 ] with-system-random .
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Change the following Factor code into Java without altering its purpose.
USE: random [ random-32 ] with-system-random .
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Port the provided Factor code into Java while preserving the original functionality.
USE: random [ random-32 ] with-system-random .
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Rewrite the snippet below in Go so it works the same as the original Factor code.
USE: random [ random-32 ] with-system-random .
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Translate this program into Go but keep the logic exactly as in Factor.
USE: random [ random-32 ] with-system-random .
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Change the programming language of this snippet from Forth to C without modifying what it does.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Generate an equivalent C version of this Forth code.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Convert this Forth block to C#, preserving its control flow and logic.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Write a version of this Forth function in C# with identical behavior.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Port the provided Forth code into C++ while preserving the original functionality.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Translate the given Forth code snippet into C++ without altering its behavior.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Translate this program into Java but keep the logic exactly as in Forth.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Produce a functionally identical Java code for the snippet given in Forth.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Change the programming language of this snippet from Forth to Python without modifying what it does.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
import random rand = random.SystemRandom() rand.randint(1,10)
Produce a language-to-language conversion: from Forth to Python, same semantics.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
import random rand = random.SystemRandom() rand.randint(1,10)
Please provide an equivalent version of this Forth code in Go.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Produce a functionally identical Go code for the snippet given in Forth.
variable rnd : randoms s" /dev/random" r/o open-file throw swap 0 do dup rnd 1 cells rot read-file throw drop rnd @ . loop close-file throw ;
package main import ( "crypto/rand" "encoding/binary" "fmt" "io" "os" ) func main() { testRandom("crypto/rand", rand.Reader) testRandom("dev/random", newDevRandom()) } func newDevRandom() (f *os.File) { var err error if f, err = os.Open("/dev/random"); err != nil { panic(e...
Translate the given Fortran code snippet into C# without altering its behavior.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Produce a functionally identical C# code for the snippet given in Fortran.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }
Ensure the translated C++ code behaves exactly like the original Fortran snippet.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Port the following code from Fortran to C++ with equivalent syntax and logic.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
#include <iostream> #include <random> int main() { std::random_device rd; std::uniform_int_distribution<long> dist; std::cout << "Random Number: " << dist(rd) << std::endl; }
Can you help me rewrite this code in C instead of Fortran, keeping it the same logically?
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Please provide an equivalent version of this Fortran code in C.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Maintain the same structure and functionality when rewriting this code in Java.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Convert the following code from Fortran to Java, ensuring the logic remains intact.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
import java.security.SecureRandom; public class RandomExample { public static void main(String[] args) { SecureRandom rng = new SecureRandom(); System.out.println(rng.nextInt()); } }
Keep all operations the same but rewrite the snippet in Python.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
import random rand = random.SystemRandom() rand.randint(1,10)
Write the same algorithm in Python as shown in this Fortran implementation.
program urandom_test use iso_c_binding, only : c_long implicit none character(len=*), parameter :: RANDOM_PATH = "/dev/urandom" integer :: funit, ios integer(c_long) :: buf open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", & iostat=ios, status="old", action="read") ...
import random rand = random.SystemRandom() rand.randint(1,10)
Produce a functionally identical C code for the snippet given in Groovy.
def rng = new java.security.SecureRandom()
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Rewrite this program in C while keeping its functionality equivalent to the Groovy version.
def rng = new java.security.SecureRandom()
#include <stdio.h> #include <stdlib.h> #define RANDOM_PATH "/dev/urandom" int main(void) { unsigned char buf[4]; unsigned long v; FILE *fin; if ((fin = fopen(RANDOM_PATH, "r")) == NULL) { fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH); return...
Write a version of this Groovy function in C# with identical behavior.
def rng = new java.security.SecureRandom()
using System; using System.Security.Cryptography; private static int GetRandomInt() { int result = 0; var rng = new RNGCryptoServiceProvider(); var buffer = new byte[4]; rng.GetBytes(buffer); result = BitConverter.ToInt32(buffer, 0); return result; }