set RNG RandomUtils Random before generating random numbers error

0 votes

I am learning to program blockchain and i am using the code:

static void Main(string[] args)
{
    try
    {
        Key privateKey = new Key(); // generate a random private key
        PubKey publicKey = privateKey.PubKey;
        Console.WriteLine(publicKey); // 0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c

        Console.WriteLine(publicKey.GetAddress(Network.Main)); // 1PrBDFfAiwqxe2izPcTsj5t4Dn5pjbvtH6
        Console.WriteLine(publicKey.GetAddress(Network.TestNet)); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq

        var publicKeyHash = publicKey.Hash;
        Console.WriteLine(publicKeyHash); // f6889b21b5540353a29ed18c45ea0031280c42cf
        var mainNetAddress = publicKeyHash.GetAddress(Network.Main);
        var testNetAddress = publicKeyHash.GetAddress(Network.TestNet);

        Console.WriteLine(mainNetAddress); // 1PrBDFfAiwqxe2izPcTsj5t4Dn5pjbvtH6
        Console.WriteLine(testNetAddress); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq

        Console.ReadLine();
    }
    catch (Exception)
    {    
        throw;
    }   
}


and when i run this, i get the following error pointing to the first line:

You must set the RNG (RandomUtils.Random) before generating random numbers

I know i have to set RNG as the error suggests but how do i do it?

Jul 5, 2018 in Blockchain by digger
• 26,740 points
591 views

1 answer to this question.

0 votes
Use the following code, you just have to initialize the generator and it will solve your problem.

RandomUtils.Random = new UnsecureRandom(); // this sets the random number generator
Key privateKey = new Key(); //this generates random private key
answered Jul 5, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

Solidity does not support returning structs in ...READ MORE

answered Jun 19, 2018 in Blockchain by aryya
• 7,450 points
1,429 views
0 votes
1 answer
0 votes
1 answer

Error in generating network sample.

I resolved this issue by downloading the ...READ MORE

answered Jul 26, 2018 in Blockchain by Perry
• 17,100 points
540 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,241 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
738 views
+1 vote
1 answer
0 votes
1 answer

JavaFX Location is not set error message

I had this problem and found this ...READ MORE

answered Sep 19, 2018 in Blockchain by slayer
• 29,350 points
9,077 views
0 votes
1 answer

Error connecting due to rpc error

In the previous version, this problem was ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,350 points
663 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP