WeixiangYan/CodeTransOcean huggingface dataset:
Task: Queue_Usage




Go: package main

import (
    "fmt"
    "queue"
)

func main() {
    q := new(queue.Queue)
    fmt.Println("empty?", q.Empty())

    x := "black"
    fmt.Println("push", x)
    q.Push(x)

    fmt.Println("empty?", q.Empty())
    r, ok := q.Pop()
    if ok {
        fmt.Println(r, "popped")
    } else {
        fmt.Println("pop failed")
    }

    var n int
    for _, x := range []string{"blue", "red", "green"} {
        fmt.Println("pushing", x)
        q.Push(x)
        n++
    }

    for i := 0; i < n; i++ {
        r, ok := q.Pop()
        if ok {
            fmt.Println(r, "popped")
        } else {
            fmt.Println("pop failed")
        }
    }
}





VB: Public Sub fifo()
    push "One"
    push "Two"
    push "Three"
    Debug.Print pop, pop, pop, empty_
End Sub
Task: Queue_Usage







Python: let my_queue = Queue()

my_queue.push!('foo')
my_queue.push!('bar')
my_queue.push!('baz')

print my_queue.pop!() 
print my_queue.pop!() 
print my_queue.pop!() 


VB: Public Sub fifo()
    push "One"
    push "Two"
    push "Three"
    Debug.Print pop, pop, pop, empty_
End Sub
Task: Queue_Usage

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
 
#include <sys/queue.h>



int main()
{
  int i;
  FIFOList head;

  TAILQ_INIT(&head);

  
  for(i=0; i < 20; i++) {
    m_enqueue(i, &head);
  }

  
  while( m_dequeue(&i, &head) )
    printf("%d\n", i);

  fprintf(stderr, "FIFO list %s\n",
      ( m_dequeue(&i, &head) ) ? 
      "had still an element" :
      "is void!");

  exit(0);
}








VB: Public Sub fifo()
    push "One"
    push "Two"
    push "Three"
    Debug.Print pop, pop, pop, empty_
End Sub
Task: Queue_Usage


C++: #include <queue>
#include <cassert> 

int main()
{
  std::queue<int> q;
  assert( q.empty() );        

  q.push(1);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(2);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(3);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.pop();                    
  assert( !q.empty() );       
  assert( q.front() == 2);    

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 3);

  q.push(4);
  assert( !q.empty() );
  assert( q.front() == 3);

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 4);

  q.pop();
  assert( q.empty() );

  q.push(5);
  assert( !q.empty() );
  assert( q.front() == 5);

  q.pop();
  assert( q.empty() );
}


C#: using System;
using System.Collections.Generic;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            
            Queue<int> queue  = new Queue<int>();
            queue.Enqueue(1);
            queue.Enqueue(3);
            queue.Enqueue(5);

            
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 

            
            bool empty = queue.Count == 0;
            Console.WriteLine(empty); 

            
            
            try
            {
                queue.Dequeue();
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine(exception.Message); 
            }
        }
    }
}
Task: Queue_Usage


C++: #include <queue>
#include <cassert> 

int main()
{
  std::queue<int> q;
  assert( q.empty() );        

  q.push(1);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(2);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(3);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.pop();                    
  assert( !q.empty() );       
  assert( q.front() == 2);    

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 3);

  q.push(4);
  assert( !q.empty() );
  assert( q.front() == 3);

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 4);

  q.pop();
  assert( q.empty() );

  q.push(5);
  assert( !q.empty() );
  assert( q.front() == 5);

  q.pop();
  assert( q.empty() );
}



Go: package main

import (
    "fmt"
    "queue"
)

func main() {
    q := new(queue.Queue)
    fmt.Println("empty?", q.Empty())

    x := "black"
    fmt.Println("push", x)
    q.Push(x)

    fmt.Println("empty?", q.Empty())
    r, ok := q.Pop()
    if ok {
        fmt.Println(r, "popped")
    } else {
        fmt.Println("pop failed")
    }

    var n int
    for _, x := range []string{"blue", "red", "green"} {
        fmt.Println("pushing", x)
        q.Push(x)
        n++
    }

    for i := 0; i < n; i++ {
        r, ok := q.Pop()
        if ok {
            fmt.Println(r, "popped")
        } else {
            fmt.Println("pop failed")
        }
    }
}
Task: Queue_Usage



C#: using System;
using System.Collections.Generic;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            
            Queue<int> queue  = new Queue<int>();
            queue.Enqueue(1);
            queue.Enqueue(3);
            queue.Enqueue(5);

            
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 

            
            bool empty = queue.Count == 0;
            Console.WriteLine(empty); 

            
            
            try
            {
                queue.Dequeue();
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine(exception.Message); 
            }
        }
    }
}



Java: import java.util.LinkedList;
import java.util.Queue;
...
Queue<Integer> queue = new LinkedList<Integer>();
System.out.println(queue.isEmpty());      

queue.add(1);
queue.add(2);
queue.add(3);
System.out.println(queue);                
System.out.println(queue.remove());       
System.out.println(queue);                
System.out.println(queue.isEmpty());
Task: Queue_Usage



C#: using System;
using System.Collections.Generic;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            
            Queue<int> queue  = new Queue<int>();
            queue.Enqueue(1);
            queue.Enqueue(3);
            queue.Enqueue(5);

            
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 

            
            bool empty = queue.Count == 0;
            Console.WriteLine(empty); 

            
            
            try
            {
                queue.Dequeue();
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine(exception.Message); 
            }
        }
    }
}


Go: package main

import (
    "fmt"
    "queue"
)

func main() {
    q := new(queue.Queue)
    fmt.Println("empty?", q.Empty())

    x := "black"
    fmt.Println("push", x)
    q.Push(x)

    fmt.Println("empty?", q.Empty())
    r, ok := q.Pop()
    if ok {
        fmt.Println(r, "popped")
    } else {
        fmt.Println("pop failed")
    }

    var n int
    for _, x := range []string{"blue", "red", "green"} {
        fmt.Println("pushing", x)
        q.Push(x)
        n++
    }

    for i := 0; i < n; i++ {
        r, ok := q.Pop()
        if ok {
            fmt.Println(r, "popped")
        } else {
            fmt.Println("pop failed")
        }
    }
}
Task: Queue_Usage

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
 
#include <sys/queue.h>



int main()
{
  int i;
  FIFOList head;

  TAILQ_INIT(&head);

  
  for(i=0; i < 20; i++) {
    m_enqueue(i, &head);
  }

  
  while( m_dequeue(&i, &head) )
    printf("%d\n", i);

  fprintf(stderr, "FIFO list %s\n",
      ( m_dequeue(&i, &head) ) ? 
      "had still an element" :
      "is void!");

  exit(0);
}






PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>
Task: Queue_Usage



C#: using System;
using System.Collections.Generic;

namespace RosettaCode
{
    class Program
    {
        static void Main()
        {
            
            Queue<int> queue  = new Queue<int>();
            queue.Enqueue(1);
            queue.Enqueue(3);
            queue.Enqueue(5);

            
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 
            Console.WriteLine(queue.Dequeue()); 

            
            bool empty = queue.Count == 0;
            Console.WriteLine(empty); 

            
            
            try
            {
                queue.Dequeue();
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine(exception.Message); 
            }
        }
    }
}




PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>
Task: Queue_Usage


C++: #include <queue>
#include <cassert> 

int main()
{
  std::queue<int> q;
  assert( q.empty() );        

  q.push(1);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(2);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.push(3);                  
  assert( !q.empty() );       
  assert( q.front() == 1 );   

  q.pop();                    
  assert( !q.empty() );       
  assert( q.front() == 2);    

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 3);

  q.push(4);
  assert( !q.empty() );
  assert( q.front() == 3);

  q.pop();
  assert( !q.empty() );
  assert( q.front() == 4);

  q.pop();
  assert( q.empty() );

  q.push(5);
  assert( !q.empty() );
  assert( q.front() == 5);

  q.pop();
  assert( q.empty() );
}





PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>
Task: Queue_Usage




Go: package main

import (
    "fmt"
    "queue"
)

func main() {
    q := new(queue.Queue)
    fmt.Println("empty?", q.Empty())

    x := "black"
    fmt.Println("push", x)
    q.Push(x)

    fmt.Println("empty?", q.Empty())
    r, ok := q.Pop()
    if ok {
        fmt.Println(r, "popped")
    } else {
        fmt.Println("pop failed")
    }

    var n int
    for _, x := range []string{"blue", "red", "green"} {
        fmt.Println("pushing", x)
        q.Push(x)
        n++
    }

    for i := 0; i < n; i++ {
        r, ok := q.Pop()
        if ok {
            fmt.Println(r, "popped")
        } else {
            fmt.Println("pop failed")
        }
    }
}



PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>
Task: Queue_Usage





Java: import java.util.LinkedList;
import java.util.Queue;
...
Queue<Integer> queue = new LinkedList<Integer>();
System.out.println(queue.isEmpty());      

queue.add(1);
queue.add(2);
queue.add(3);
System.out.println(queue);                
System.out.println(queue.remove());       
System.out.println(queue);                
System.out.println(queue.isEmpty());      


PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>
Task: Queue_Usage






PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>


Python: let my_queue = Queue()

my_queue.push!('foo')
my_queue.push!('bar')
my_queue.push!('baz')

print my_queue.pop!() 
print my_queue.pop!() 
print my_queue.pop!()
Task: Queue_Usage






PHP: <?php
$queue = new SplQueue;
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // empty test - returns true

$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
echo $queue->dequeue(), "\n";                     // returns 1
echo $queue->isEmpty() ? 'true' : 'false', "\n";  // returns false
?>



VB: Public Sub fifo()
    push "One"
    push "Two"
    push "Three"
    Debug.Print pop, pop, pop, empty_
End Sub
Task: Random number generator (device)

C: #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 EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}



C#: 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;
}
Task: Random number generator (device)

C: #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 EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}
Task: Random number generator (device)

C: #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 EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}





Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}
Task: Random number generator (device)

C: #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 EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}







Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}


C#: 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;
}
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}



Go: 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(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}




Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}






Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)



C#: 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;
}


Go: 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(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}
Task: Random number generator (device)



C#: 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;
}



Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}
Task: Random number generator (device)



C#: 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;
}





Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)




Go: 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(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}


Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}
Task: Random number generator (device)





Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}



Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)




Go: 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(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}




Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)

C: #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 EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}




Go: 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(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}