-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXorshift.m5b
1 lines (1 loc) · 8.88 KB
/
Xorshift.m5b
1
{"category":"Xorshift","color":"#5cc3ff","blocks":["__Xorshift_generate32","__Xorshift_generate96","__Xorshift_generate128"],"jscode":"// Block __Xorshift_generate32\nvar __Xorshift_generate32_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"generate32\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"value\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"value\"\n }\n ],\n \"colour\": \"#5cc3ff\"\n};\n\nwindow['Blockly'].Blocks['__Xorshift_generate32'] = {\n init: function() {\n this.jsonInit(__Xorshift_generate32_json);\n }\n};\n\nwindow['Blockly'].Python['__Xorshift_generate32'] = function(block) {\n var seed = Blockly.Python.valueToCode(block, 'seed', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `${seed} ^= ${seed} << 13;\n${seed} ^= ${seed} >> 17;\n${seed} ^= ${seed} << 5;\n${seed} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed};\n` + \"\\n\";\n};\n\n// Block __Xorshift_generate96\nvar __Xorshift_generate96_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"generate96\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed1\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed1\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed2\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed2\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed3\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed3\"\n }\n ],\n \"message4\": \"%1 %2\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \"value\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"value\"\n }\n ],\n \"colour\": \"#5cc3ff\"\n};\n\nwindow['Blockly'].Blocks['__Xorshift_generate96'] = {\n init: function() {\n this.jsonInit(__Xorshift_generate96_json);\n }\n};\n\nwindow['Blockly'].Python['__Xorshift_generate96'] = function(block) {\n var seed1 = Blockly.Python.valueToCode(block, 'seed1', Blockly.Python.ORDER_NONE);\nvar seed2 = Blockly.Python.valueToCode(block, 'seed2', Blockly.Python.ORDER_NONE);\nvar seed3 = Blockly.Python.valueToCode(block, 'seed3', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `t = (${seed1} ^ (${seed1} << 3)) ^ (${seed2} ^ (${seed2}>> 19)) ^ (${seed3} ^ (${seed3} << 6));\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = t;\n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed3};` + \"\\n\";\n};\n\n// Block __Xorshift_generate128\nvar __Xorshift_generate128_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"generate128\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed1\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed1\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed2\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed2\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed3\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed3\"\n }\n ],\n \"message4\": \"%1 %2\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \"seed4\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"seed4\"\n }\n ],\n \"message5\": \"%1 %2\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \"value\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"value\"\n }\n ],\n \"colour\": \"#5cc3ff\"\n};\n\nwindow['Blockly'].Blocks['__Xorshift_generate128'] = {\n init: function() {\n this.jsonInit(__Xorshift_generate128_json);\n }\n};\n\nwindow['Blockly'].Python['__Xorshift_generate128'] = function(block) {\n var seed1 = Blockly.Python.valueToCode(block, 'seed1', Blockly.Python.ORDER_NONE);\nvar seed2 = Blockly.Python.valueToCode(block, 'seed2', Blockly.Python.ORDER_NONE);\nvar seed3 = Blockly.Python.valueToCode(block, 'seed3', Blockly.Python.ORDER_NONE);\nvar seed4 = Blockly.Python.valueToCode(block, 'seed4', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `t = ${seed1} ^ (${seed1} << 11);\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = ${seed4};\n${seed3} = t;\n${seed4} = (${seed4} ^ (${seed4} >> 19)) ^ (t ^ (t >> 8)); \n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${seed4} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed4};` + \"\\n\";\n};\n\n","code":{"generate32":["window['Blockly'].Python['__Xorshift_generate32'] = function(block) {\n var seed = Blockly.Python.valueToCode(block, 'seed', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `${seed} ^= ${seed} << 13;\n${seed} ^= ${seed} >> 17;\n${seed} ^= ${seed} << 5;\n${seed} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed};\n` + \"\\n\";\n};\n\n","${seed} ^= ${seed} << 13;\n${seed} ^= ${seed} >> 17;\n${seed} ^= ${seed} << 5;\n${seed} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed};\n"],"generate96":["window['Blockly'].Python['__Xorshift_generate96'] = function(block) {\n var seed1 = Blockly.Python.valueToCode(block, 'seed1', Blockly.Python.ORDER_NONE);\nvar seed2 = Blockly.Python.valueToCode(block, 'seed2', Blockly.Python.ORDER_NONE);\nvar seed3 = Blockly.Python.valueToCode(block, 'seed3', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `t = (${seed1} ^ (${seed1} << 3)) ^ (${seed2} ^ (${seed2}>> 19)) ^ (${seed3} ^ (${seed3} << 6));\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = t;\n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed3};` + \"\\n\";\n};\n\n","t = (${seed1} ^ (${seed1} << 3)) ^ (${seed2} ^ (${seed2}>> 19)) ^ (${seed3} ^ (${seed3} << 6));\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = t;\n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed3};"],"generate128":["window['Blockly'].Python['__Xorshift_generate128'] = function(block) {\n var seed1 = Blockly.Python.valueToCode(block, 'seed1', Blockly.Python.ORDER_NONE);\nvar seed2 = Blockly.Python.valueToCode(block, 'seed2', Blockly.Python.ORDER_NONE);\nvar seed3 = Blockly.Python.valueToCode(block, 'seed3', Blockly.Python.ORDER_NONE);\nvar seed4 = Blockly.Python.valueToCode(block, 'seed4', Blockly.Python.ORDER_NONE);\nvar value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_NONE);\n return `t = ${seed1} ^ (${seed1} << 11);\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = ${seed4};\n${seed3} = t;\n${seed4} = (${seed4} ^ (${seed4} >> 19)) ^ (t ^ (t >> 8)); \n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${seed4} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed4};` + \"\\n\";\n};\n\n","t = ${seed1} ^ (${seed1} << 11);\n${seed1} = ${seed2};\n${seed2} = ${seed3};\n${seed3} = ${seed4};\n${seed3} = t;\n${seed4} = (${seed4} ^ (${seed4} >> 19)) ^ (t ^ (t >> 8)); \n${seed1} %= int(\"FFFFFFFF\", 16);\n${seed2} %= int(\"FFFFFFFF\", 16);\n${seed3} %= int(\"FFFFFFFF\", 16);\n${seed4} %= int(\"FFFFFFFF\", 16);\n${value} = ${seed4};"]}}