True random numbers in Sol10


 
Thread Tools Search this Thread
Operating Systems Solaris True random numbers in Sol10
# 1  
Old 07-26-2016
True random numbers in Sol10

Hi everyone



I just got my hands on a T5120 running Sol10. As far as I've read, the T2 chip has a built-in hardware number generator. My question is: how can I access it to get random numbers in either C or Fortran? I'm using Sun Studio 12.4.



I am currently trying to write an application for simulating stochastic motion of Brownian particles and being able to get true random numbers instead of pseudo-random numbers is of great use for me.


Thank you in advance
# 2  
Old 07-26-2016
A portable method is /dev/random.
See this Oracle doc.
# 3  
Old 07-26-2016
/dev/random has a limitation - a good one. When the entropy pool is empty, it will not return values. It blocks on read(). /dev/urandom is the same as /dev/random except that when the entropy pool has no more values it will return a value anyway.

The entropy pool is a kernel-only readable object.
# 4  
Old 07-26-2016
I'll be more specific.

Say I want to get a random number in fortran through the following statement 'call random_number(arg)'. The question is: how can I make sure that this call does not return a pseudo-random number but instead a random number generated by the HARDWARE "true" random number generator of the SPARC T2 chip?

I need this for simulations so I do require true random numbers.

Thanks
# 5  
Old 07-26-2016
Hi.

Some suggestions:
Code:
Sources of true random sequences
        0) AVOID /dev/random /dev/urandom:

        The kernel random-number generator is designed to produce
        a small amount of high-quality seed material to seed a
        cryptographic pseudo- random number generator (CPRNG). It
        is designed for security, not speed, and is poorly suited
        to generating large amounts of random data. Users should be
        very economical in the amount of seed material that they
        read from /dev/urandom (and /dev/random); unnecessarily
        reading large quantities of data from this device will have
        a negative impact on other users of the device.
        -- excerpt from man urandom

        1) http://www.fourmilab.ch/hotbits/

        2) http://random.irb.hr/index.php

        3) https://www.random.org/

        4) perl module: 
           Net::Random - get random data from online sources
           Sample output, 5 integers (min, max vary):
            From fourmilab.ch   : 600 1785 384 1466 1212
            From qrng.anu.edu.au: 2498 2234 2071 2573 2868
            From random.org     : 7014 5940 5911 6289 3246

Best wishes ... cheers, drl

Last edited by drl; 07-26-2016 at 05:44 PM..
# 6  
Old 07-26-2016
@drl: You should avoid using Linux documentation with Solaris. It might not be relevant which is especially the case in this thread.

@toguro123 You should first make sure the n2rng provider (kernel module) is enabled:

Code:
# cryptoadm list | grep rng

Then you might have a look to the n2rng provider kernel statistics and see if they increase after your calls.

Code:
# kstat -m n2rng

I believe cryptoadm also let you configure /dev/random to only use the hardware generator but I haven't the precise command to run. You might have a look to cryptoadm documentation.
# 7  
Old 07-26-2016
Hi, jlliagre.
Quote:
Originally Posted by jlliagre
@drl: You should avoid using Linux documentation with Solaris. It might not be relevant which is especially the case in this thread. ...
OK, thanks for the comment. I'll add an excerpt from Solaris. It looks quite similar to me, but it might be more on point for Solaris users. I'm trying emphasize that /dev/random & /dev/urandom are probably not good sources for true random sequences, and that the net resources mentioned are such sources, and that they would (generally) be portable.
Code:
Sources of true random sequences                                                
        0) AVOID /dev/random /dev/urandom:

        The kernel random-number generator is designed to produce
        a small amount of high-quality seed material to seed a
        cryptographic pseudo- random number generator (CPRNG). It
        is designed for security, not speed, and is poorly suited
        to generating large amounts of random data. Users should be
        very economical in the amount of seed material that they
        read from /dev/urandom (and /dev/random); unnecessarily
        reading large quantities of data from this device will have
        a negative impact on other users of the device.
        -- excerpt from man urandom (linux)

        Applications retrieve random bytes by reading /dev/random
        or /dev/uran- dom. The /dev/random interface returns random
        bytes only when suffi- cient amount of entropy has been
        collected. If there is no entropy to produce the requested
        number of bytes, /dev/random blocks until more entropy can
        be obtained. Non-blocking I/O mode can be used to disable
        the blocking behavior. The /dev/random interface also
        supports poll(2). Note that using poll(2) does not increase
        the speed at which random numbers can be read.
        -- excerpt from man urandom (Solaris)

        1) http://www.fourmilab.ch/hotbits/

        2) http://random.irb.hr/index.php

        3) https://www.random.org/

        4) perl module: 
           Net::Random - get random data from online sources
           Sample output, 5 integers (min, max vary):
            From fourmilab.ch   : 600 1785 384 1466 1212
            From qrng.anu.edu.au: 2498 2234 2071 2573 2868
            From random.org     : 7014 5940 5911 6289 3246

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Random numbers

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! Write a shell script that will take the sum of two random number? Ex: Random n1 +Random n2 = result i tries to write it but i had some dufficulties ... (3 Replies)
Discussion started by: renegade755
3 Replies

2. Programming

How to fill a memory with random numbers in C

Hi, I have a parametrized memory mem. I want to fill this memory with random numbers with respect to the data_width. can anyone help me on this.. (3 Replies)
Discussion started by: vdhingra123
3 Replies

3. Shell Programming and Scripting

Random float numbers in BASH

Hi people :) I'm learning shell scripting using bash and I want to generate 4 floating point number with 5 decimal places and write them to a file and a variable. I've done all this except the $RAMDOM enviroment variable does not generate a float number but a integrer. I hope you could... (3 Replies)
Discussion started by: pharaoh
3 Replies

4. Programming

Random numbers in parent/child?

Hi I'm trying to generate random numbers both in parent process and the child process. But I get the same random number in both processes. Why doesn't it generate different numbers altough I seed random number generator? Here's my code: #include <stdio.h> #include <unistd.h> #include... (2 Replies)
Discussion started by: xyzt
2 Replies

5. Shell Programming and Scripting

Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ... (9 Replies)
Discussion started by: phil_heath
9 Replies

6. Shell Programming and Scripting

Random Numbers - Perl

Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz. In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength input and out put will be like this chrno start end... (3 Replies)
Discussion started by: repinementer
3 Replies

7. Shell Programming and Scripting

Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed (2 Replies)
Discussion started by: wakhan
2 Replies

8. Programming

How to set constrain on random numbers in c

Hi, I am currently trying to generate multiple random numbers in C for different variable:- die1=1+(rand()%5); die2=1+(rand()%5); die3=1+(rand()%5); die4=1+(rand()%5); But I need to contrain the total of die1, die2,die3 and die4 to be 5 as well. If i insert die1+die2+die3+die4=5, i do... (6 Replies)
Discussion started by: ahjiefreak
6 Replies

9. UNIX for Dummies Questions & Answers

Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks (8 Replies)
Discussion started by: asal_email
8 Replies
Login or Register to Ask a Question