示例#1
0
def choose_numbers(n, _max, _min):
    """Pick n distinct integers in the range (max, min) inclusive

    The calling code should handle any exception raised by random.org
    """
    r = RandomOrgClient(getattr(settings, "RANDOMDOTORG_API_KEY"))
    numbers = r.generate_integers(n=n, max=_max, min=_min, replacement=False)
    return numbers
示例#2
0
 def roll(self, nb=0, sides=6, modifier=0):
     r = RandomOrgClient(self.api_key)
     if sides == 'F':
         dicelist = r.generate_strings(nb, 1, ' -+')
         return FudgeDiceResult(dicelist, modifier)
     else:
         dicelist = r.generate_integers(nb, 1, sides)
         return DiceResult(dicelist, modifier)
示例#3
0
 def roll(self, nb=0, sides=6, modifier=0):
     r = RandomOrgClient(self.api_key)
     if sides == 'F':
         dicelist = r.generate_strings(nb, 1, ' -+')
         return FudgeDiceResult(dicelist, modifier)
     else:
         dicelist = r.generate_integers(nb, 1, sides)
         return DiceResult(dicelist, modifier)
示例#4
0
文件: simcon.py 项目: lorinma/simcon
 def norm_random(self, mean, std):
     """
     generate random numbers, if the RandomOrg token is used out, use numpy
     :param mean:
     :param std:
     :return:
     """
     try:
         r = RandomOrgClient(self.random_key)
         # mean = v, std = std, last para is the extreme digit
         # see https://github.com/RandomOrg/JSON-RPC-Python/blob/master/rdoclient/rdoclient.py
         ran = r.generate_gaussians(1, mean, std, 5)[0]
     except:
         ran = np.random.normal(mean, std, 1)[0]
     return ran
示例#5
0
def get_roc(api_key=config.API_KEY):
    """
    Get instance of RandomOrgClient for testing.

    :param api_key: API key to fetch API client
    :return: instance of ROC
    """

    try:
        roc = RandomOrgClient(api_key)
        return roc

    except (ValueError, AttributeError) as e:
        print(e)
def initialize_client(api_key, blocking_timeout=None, http_timeout=None, cached=False, live_results=False, **kwargs):
    r = None
    c = None
    if has_capacity(api_key):
        if blocking_timeout and http_timeout:
            r = RandomOrgClient(api_key, blocking_timeout, http_timeout)

        if cached:
            if r is None:
                r = RandomOrgClient(api_key, blocking_timeout=60.0 * 60.0, http_timeout=30.0)
            cache_size = kwargs['cache_size']
            cache_min = kwargs['cache_min']
            cache_max = kwargs['cache_max']
            # print(kwargs)
            c = r.create_integer_cache(cache_size, cache_min, cache_max)


        elif live_results:
            r = RandomOrgClient(api_key, blocking_timeout=0.0, http_timeout=10.0, serialized=False)
    return r, c
 def setUp(self):
     value_between_0_and_1000000000 = 3000
     request = RandomOrgClient('')
     request.integer_generator = MagicMock(
         return_value=value_between_0_and_1000000000)
     self.random = RandomFromRandomOrg(request)
def get_capacity_left(api_key):
    r = RandomOrgClient(api_key)
    bits = r.get_bits_left()
    reqs = r.get_requests_left()
    return reqs, bits
示例#9
0
 def clientRandomOrg(self):
     return RandomOrgClient('8691ad96-9cb8-4d3b-bc14-3f9c2f9de1b6')
示例#10
0
#!/usr/bin/env python3

import configparser
from rdoclient import RandomOrgClient

cpr = configparser.ConfigParser()
cpr.read("que.ini")

NSTUDENTS = int(cpr['class']['students'])
NQUESTIONS = int(cpr['course']['questions'])
APIKEY = cpr['randorg']['api_key']
r: RandomOrgClient = RandomOrgClient(APIKEY)

if NQUESTIONS < NSTUDENTS * 2:
    print("Repeating questions are not yet implemented")
    quit(1)

shuffled: list[int] = r.generate_integer_sequences(1, NSTUDENTS * 2, 1,
                                                   NQUESTIONS, False)[0]

for q1, q2 in zip(shuffled[:NSTUDENTS], shuffled[NSTUDENTS:]):
    if q1 > q2:
        q1, q2 = q2, q1
    print(q1, q2, sep='\t')
示例#11
0
from django.conf import settings
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.mixins import UserPassesTestMixin
from django.contrib.auth.models import User, \
    Group  # need to import Group from https://stackoverflow.com/a/6288863/5434744
from django.db.models import Count  # need to import Count from https://stackoverflow.com/a/6525869/5434744
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.views import generic
from django.views.generic import TemplateView

from rdoclient import RandomOrgClient

from .models import Drawing, Ticket, Number, Results, Answer, Scratchoff

r = RandomOrgClient(settings.RANDOM_ORG_API_KEY)


# Create your views here.
class DrawingsView(UserPassesTestMixin, generic.ListView):
    template_name = 'lottery/drawings.html'
    context_object_name = 'drawing_list'
    login_url = '/login'

    def get_queryset(self):
        return Drawing.objects.order_by('-end_date')[:5]

    def test_func(self):
        return not self.request.user.is_anonymous and not userIsKiosk(
            self.request.user)
示例#12
0
    'atanh': math.atanh,
    'cosh': math.cosh,
    'sinh': math.sinh,
    'tanh': math.tanh,
    'erf': math.erf,
    'erfc': math.erfc,
    'gamma': math.gamma,
    'lgamma': math.lgamma,
    'pi': math.pi,
    'e': math.e,
    'tau': math.tau,
    'inf': math.inf,
    'nan': math.nan
}
# Randorg
rdo: RandomOrgClient = RandomOrgClient(os.getenv('RANDORG_API_KEY'))


def get_role(guild: discord.Guild, id_num: int) -> discord.Role:
    return discord.utils.get(guild.roles, id=id_num)


def get_emoji(guild: discord.Guild,
              name: str,
              fallback_id: int = None) -> Union[str, discord.Emoji]:
    emoji: discord.Emoji = discord.utils.get(guild.emojis, name=name)
    if not emoji:
        return f'<:{name}:{fallback_id}>'
    return emoji

示例#13
0
from __future__ import print_function
from rdoclient import RandomOrgClient
r=RandomOrgClient("0c39b793-4783-42d1-ae19-c465c076fa9b")
win1=0
win2=0
print("We are going to play a game called dice duels! Dice duels is a game where two players participate in rolling dice. The first player rolls and then the second, whoever\nhas the higher roll wins that round. It's a best of three games so whoever wins two rounds first wins the game.")
player1=str(raw_input("Enter Player 1's name: "))
player2=str(raw_input("Enter player 2's name: "))
while(win1!=2 and win2!=2):
	roll1=r.generate_integers(1,1,6)
	output1=roll1[0]
	player1roll=raw_input("{} type roll to roll!\n>".format(player1))
	while(player1roll!="roll"):
		player1roll=raw_input("{} type roll to roll!\n>".format(player1))
	print("{} got {}.".format(player1,output1))
	roll2=r.generate_integers(1,1,6)
	output2=roll2[0]
	player2roll=raw_input("{} type roll to roll!\n>".format(player2))
	while(player2roll!="roll"):
		player2roll=raw_input("{} type roll to roll!\n>".format(player2))
	print("{} got {}.".format(player2,output2))
	if(roll1>roll2):
		print("Nice, {} one this round!".format(player1))
		win1+=1
		print("The score is {} to {}.".format(win1,win2))
	if(roll1<roll2):
		print("Nice, {} one this round!".format(player2))
		win2+=1
		print("The score is {} to {}.".format(win1,win2))
	if(roll1==roll2):
		print("Both players rolled the same number, this round does not count for either player.")
from rdoclient import RandomOrgClient
r = RandomOrgClient(YOUR_API_KEY_HERE)
r.generate_integers(5, 0, 10)

print(r)
示例#15
0
from __future__ import print_function
from rdoclient import RandomOrgClient

r = RandomOrgClient("0c39b793-4783-42d1-ae19-c465c076fa9b")
x = r.generate_integers(5, 0, 10)
y = x[1]
print(y)