Posts random.org call
Post
Cancel

random.org call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//test

			$(function() {

				//button click
				$('#btn').on('click', function(e) {

					if ($("#txt_how_many").val().length == 0 || 
					$("#txt_min").val().length == 0 ||
					$("#txt_max").val().length == 0)
					{alert( "Please fill textboxes!");
					return;
					}
					//window.open("http://www.random.org/integers/?num=" + $("#txt_how_many").val() + "&min=" + $("#txt_min").val() + "&max=" + $("#txt_max").val() + "&col=1&base=10&format=plain&rnd=new")

		 			$.ajax({
		                url: 'https://api.random.org/json-rpc/1/invoke',
		                dataType : 'json',
		                contentType: "application/json-rpc", 
		                type: 'POST',
		                data:  JSON.stringify({
		                    "jsonrpc": "2.0",
		                    "method": "generateSignedIntegers",
		                    "params": {
		                        "apiKey": "x-x-x-8b27-x", //get your http://api.random.org/api-keys/beta
		                        "n": $("#txt_how_many").val(),
		                        "min": $("#txt_min").val(),
		                        "max":  $("#txt_max").val(),
								"replacement" : false, //by default true - the resulting numbers may contain duplicate values
								"base" : 10
		                    },
		                    "id": 14215333
		                    })

		            })
		            .done(function (data, status, request)
		            {
		            	console.log(data);
		            	if (data.error)
		            	{
		            		alert(data.error.message);
		            	}

		            	if (data)
		            		if (data.result)
		            			if (data.result.random)
			            		{
			            			var nos = data.result.random.data;
			            			//console.log(nos);
			            			var outp = "";
			            			for(var no in nos)
			            			{
			            				outp += nos[no] + "  
";
			            				//console.log(nos[no]);
			            			}

			            			$("#myDIV").html(outp);
			            		}

		            })
		            .fail(function (request, status, error)
		            {
		                alert("Failed " + error);
		            });

			});

		});

		<div style="margin: 0 auto;width:500px">
			  <div class="form-group">
			    <label for="exampleInputEmail1">Generate Numbers : </label>
			    <input class="form-control" id="txt_how_many" placeholder="Numbers">
			  </div>

			  <div class="form-group">
			    <label>Minimum Number : </label>
			    <input class="form-control" id="txt_min" value="1" placeholder="Minimum Number">
			  </div>

			  <div class="form-group">
			    <label>Maximum Number : </label>
			    <input class="form-control" id="txt_max" placeholder="Maximum Number">
			  </div>

				<button id="btn">
					Generate
				</button>

<div id="myDIV" style="text-align: center"></div>  

		</div>

origin - http://www.pipiscrew.com/?p=3086 js-random-org-call

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags