1

I need to generate 10 unique random numbers between 0 to 100 in my smart contract.

For this I've decided to utilise Oracalize and one of the datasource called WolframAlpha. This is how I use it:

function loadNewRandomNumbers() public payable {
    oraclizeID = oraclize_query("WolframAlpha", "10 unique random numbers between 0 and 100");
}

I've deployed this to Ropsten test net and executed the loadNewRandomNumbers function and everything worked and I have the result from calling the wolfram alpha api datasource:

enter image description here

This is great so far; but I need to parse the string (json-like) response - so that I can use it; Ideally parse the response into an uint array.

How can I go about doing this? Is there a way parse the above string response into a usable format?

0

You can use a callback function to separate the ID from the string, as in this example. Then you can use a tool like solidity-util for parsing the string, as explained in this question.

Alternately Oraclize has a parsing helper for JSON, but I'm not sure if/how that works with Wolfram.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.