split/slice uint

garryplaysgarryplays New ZealandMember Posts: 5
I have a couple of keccaks, which could be reduced to one, if I would find a cheap way to get parts of the created uint.

pragma solidity ^0.4.19;

contract test {
function test() {


function sup() returns (uint test) {
uint _test = uint(keccak256("wow"));
return _test;
Which returns me a sweet random number: 13483274892375982735325
Now the plan is that instead of calling keccak 5 times with different "seeds" I could take that number apart and get something like:
1348, 3274, 8923 etc.
which I then use for my random number e.g.: 1348 % 10

I am lost.


  • garryplaysgarryplays New ZealandMember Posts: 5
    Here my best attempt.

    pragma solidity ^0.4.19;

    contract test {

    event randomNumbers(uint[8] numbers, uint[8] randomNumbers);

    function testa() public returns (uint[8] bla) {

    //uint something = 12345678123456781234567812345678;
    uint something = uint(keccak256("rockandroll"));

    uint[8] memory array;
    uint[8] memory random;

    for(uint i=0; i<8; i++) {
    uint digit = something % 10000;
    // do something with digit
    array[i] = digit;
    something /= 10000;
    random[i] =digit % 10;


    return array;
Sign In or Register to comment.