random number generator - How to determine a coin toss online?

06
2014-04
  • Aram Kocharyan

    What resources can I use if I'm trying to settle a coin flip online? Obviously, a coin toss app won't work if it only displays the result to me - the other party should also see it. And we can't meet up in person. Sharing screens came to mind, but I was wondering if there's some session sharing website that handles things like this.

  • Answers
  • Mason Heller

    There's a site at http://flipfor.us/ that will allow you to flip a coin and it will email the result to you and your opponent. For a one-off, it's useful

    I'd consider building a site that allows two users to log in and flip coins together, but I have way too many little projects already. :P

  • Lèse majesté

    You could create a shared Google Docs spreadsheet and enter this into one of the cells:

    =ROUND(RAND())
    

    Or...

    =IF(ROUND(RAND()), "Joe", "Sally")
    

    Every time you save (or rather Google Docs autosaves), the random number generator will generate a new number. So to do a coin toss just type a random character into any (other) cell and hit enter. Both users will see the same result.


    Some not so simple but more interesting solutions...

    You could try generating 2 random stock symbols:

    CONCATENATE(
      CHAR(RANDBETWEEN(65,90)),
      CHAR(RANDBETWEEN(65,90)),
      CHAR(RANDBETWEEN(65,90))
    )
    

    and use GoogleFinance(..., "price") to look up which is higher. Sort of a Wall Street high card draw...

    However, do not combine both formulas in one cell, because this will cause an infinite loop: GoogleFinance() will fetch the stock price, changing the spreadsheet, causing the RANDBETWEEN() functions to recalculate, causing the stock symbol to be changed, causing GoogleFinance() to fetch a new value...

    You can however, automate this process safely by using JavaScript (Google Apps Script) to generate the random letters.

    You can also use Google Apps Script to track the number of times the random number generator has been run in the first solution to prevent cheating (or simply modify the formula to insert a neutral value as a simple binary counter).


    Another solution would be to take a random word or string, add the CODE() value of each character, and select the least significant bit. If you're really paranoid, have one person pick the string, and have the other pick which bit position to use.


  • Related Question

    how do you make a letter password generator in batch?
  • mendez

    I'm having a hard time figuring out how to make a password generator with random letters in it. For example, ASWED-ASDWAD-EFEST. So far I can only make random numbers by using the code

    @echo off
    
    :password
    
    echo %random%-%random%-%random
    pause
    goto password
    

    PS: my OS is windows vista.

    all help will be appreciated.


  • Related Answers
  • Sathya

    There is a discussion here that you could adapt for your purposes.

    @Echo Off
    Setlocal EnableDelayedExpansion
    Set _RNDLength=8
    Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
    Set _Str=%_Alphanumeric%987654321
    :_LenLoop
    IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
    SET _tmp=%_Str:~9,1%
    SET /A _Len=_Len+_tmp
    Set _count=0
    SET _RndAlphaNum=
    :_loop
    Set /a _count+=1
    SET _RND=%Random%
    Set /A _RND=_RND%%%_Len%
    SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
    If !_count! lss %_RNDLength% goto _loop
    Echo Random string is !_RndAlphaNum!
    

    TheOutcaste expains the above:

    I've modified it so you can easily specify the length, and add or remove characters without having to change any other part of the code.

    For example, you might not want to use both 0 and O (zero and Uppercase O), or 1 and l (one and lowercase L).

    You can use punctuation except for these characters:

    ! % ^ & < >
    

    You can use ^ and %, but must enter them in the _Alphanumeric variable twice as ^^ or %%. However, if you want to use the result (_RndAlphaNum) later in the batch file (other than Echoing to the screen), they might require special handling.

    You can even use a space, as long as it's not the last character in the string. If it ends up as the last character in the generated string though, it will not be used, so you would only have 7 characters.

  • Scott Chamberlain

    here is mine. Ameture, but it works

    @Echo OFF
    @echo Would You Like Me To Make You A Password? Type Your Response And Press Enter.
    set /p ans=
    if %ans%==yes (goto yes
    )
    if %ans%==no (goto exit
    )
    
    :exit
    cls
    @echo Are You Sure?
    set /p ans=
    if %ans%==yes (goto exit
    )
    if %ans% NEQ yes (goto yes
    )
    :yes
    cls 
    @echo Loading...
    
    @echo OFF
    ping localhost -n 4 > Nul
    goto hardpart
    
    
    
    
    
    :hardpart
    @echo OFF
    cls
    @echo Get a peice of paper so you will remember
    pause
    cls
    @echo OFF
    set /A r=%RANDOM% %% 25 + 1
    cls
    if %r%==1 goto 1
    if %r%==2 goto 2
    if %r%==3 goto 3
    if %r%==4 goto 4
    if %r%==5 goto 5
    if %r%==6 goto 6
    if %r%==7 goto 7
    if %r%==8 goto 8
    if %r%==9 goto 9
    if %r%==10 goto 10
    if %r%==11 goto 11
    if %r%==12 goto 12
    if %r%==13 goto 13
    if %r%==14 goto 14
    if %r%==15 goto 15
    if %r%==16 goto 16
    if %r%==17 goto 17
    if %r%==18 goto 18
    if %r%==19 goto 19
    if %r%==20 goto 20
    if %r%==21 goto 21
    if %r%==22 goto 22
    if %r%==23 goto 23
    if %r%==24 goto 24
    if %r%==25 goto 25
    if %r%==26 goto 26
    :1 
    @echo 1st letter is a
    goto number2
    pause
    goto number2
    :2
    @echo 1st letter is b
    pause
    goto number2
    :3
    @echo 1st letter is c
    pause
    goto number2
    :4
    @echo 1st letter is d
    pause
    goto number2
    :5
    @echo 1st letter is e
    pause
    goto number2
    :6
    @echo 1st letter is f
    pause
    goto number2
    :7
    @echo 1st letter is g
    pause
    goto number2
    :8
    @echo 1st letter is h
    pause
    goto number2
    :9
    @echo 1st letter is i
    pause
    goto number2
    :10
    @echo 1st letter is j
    pause
    goto number2
    :11
    @echo 1st letter is k
    pause
    goto number2
    :12
    @echo 1st letter is l
    pause
    goto number2
    :13
    @echo 1st letter is m
    pause
    goto number2
    :14
    @echo 1st letter is n
    pause
    goto number2
    :15
    @echo 1st letter is o
    pause
    goto number2
    :16
    @echo 1st letter is p
    pause
    goto number2
    :17
    @echo 1st letter is q
    pause
    goto number2
    :18
    @echo 1st letter is r
    pause
    goto number2
    :19
    @echo 1st letter is s
    pause
    goto number2
    :20
    @echo 1st letter is t
    pause
    goto number2
    :21
    @echo 1st letter is u
    pause
    goto number2
    :22
    @echo 1st letter is v
    pause
    goto number2
    :23
    @echo 1st letter is w
    pause
    goto number2
    :24
    @echo 1st letter is x
    pause
    goto number2
    :25
    @echo 1st letter is y
    pause
    goto number2
    :26
    @echo 1st letter is z
    pause
    goto number2
    :number2
    @echo OFF
    set /A s=%RANDOM% %% 25 + 1
    cls
    if %s%==1 goto 1a
    if %s%==2 goto 2a
    if %s%==3 goto 3a
    if %s%==4 goto 4a
    if %s%==5 goto 5a
    if %s%==6 goto 6a
    if %s%==7 goto 7a
    if %s%==8 goto 8a
    if %s%==9 goto 9a
    if %s%==10 goto 10a
    if %s%==11 goto 11a
    if %s%==12 goto 12a
    if %s%==13 goto 13a
    if %s%==14 goto 14a
    if %s%==15 goto 15a
    if %s%==16 goto 16a
    if %s%==17 goto 17a
    if %s%==18 goto 18a
    if %s%==19 goto 19a
    if %s%==20 goto 20a
    if %s%==21 goto 21a
    if %s%==22 goto 22a
    if %s%==23 goto 23a
    if %s%==24 goto 24a
    if %s%==25 goto 25a
    if %s%==26 goto 26a
    :1a 
    @echo The next letter is a
    pause
    goto number2
    :2a
    @echo The next letter is b
    pause
    goto number2
    :3a
    @echo The next letter is c
    pause
    goto number2
    :4a
    @echo The next letter is d
    pause
    goto number2
    :5a
    @echo The next letter is e
    pause
    goto number2
    :6a
    @echo The next letter is f
    pause
    goto number2
    :7a
    @echo The next letter is g
    pause
    goto number2
    :8a
    @echo The next letter is h
    pause
    goto number2
    :9a
    @echo The next letter is i
    pause
    goto number2
    :10a
    @echo The next letter is j
    pause
    goto number2
    :11a
    @echo The next letter is k
    pause
    goto number2
    :12a
    @echo The next letter is l
    pause
    goto number2
    :13a
    @echo The next letter is m
    pause
    goto number2
    :14a
    @echo The next letter is n
    pause
    goto number2
    :15a
    @echo The next letter is o
    pause
    goto number2
    :16a
    @echo The next letter is p
    pause
    goto number2
    :17a
    @echo The next letter is q
    pause
    goto number2
    :18a
    @echo The next letter is r
    pause
    goto number2
    :19a
    @echo The next letter is s
    pause
    goto number2
    :20a
    @echo The next letter is t
    pause
    goto number2
    :21a
    @echo The next letter is u
    pause
    goto number2
    :22a
    @echo The next letter is v
    pause
    goto number2
    :23a
    @echo The next letter is w
    pause
    goto number2
    :24a
    @echo The next letter is x
    pause
    goto number2
    :25a
    @echo The next letter is y
    pause
    goto number2
    :26a
    @echo The next letter is z
    pause
    goto number2
    
  • Scott Chamberlain
    rem 16 stings pwd
    
    setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    set alfanum=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
    
    set pwd=
    FOR /L %%b IN (0, 1, 16) DO (
    SET /A rnd_num=!RANDOM! * 62 / 32768 + 1
    for /F %%c in ('echo %%alfanum:~!rnd_num!^,1%%') do set pwd=!pwd!%%c
    )
    
    echo pwd=%pwd%
    
  • Tog

    I edited pauls one:

    @Echo Off
    color 0a
    set /P lengthnumberuser="What length do you want your password to be?   "
    pause
    cls
    Setlocal EnableDelayedExpansion
    Set _RNDLength=%lengthnumberuser%
    Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
    Set _Str=%_Alphanumeric%987654321
    :_LenLoop
    IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
    SET _tmp=%_Str:~9,1%
    SET /A _Len=_Len+_tmp
    Set _count=0
    SET _RndAlphaNum=
    :_loop
    Set /a _count+=1
    SET _RND=%Random%
    Set /A _RND=_RND%%%_Len%
    SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
    If !_count! lss %_RNDLength% goto _loop
    Echo Password is: is !_RndAlphaNum!
    
    pause