KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Help with a random 50/50 "coin flip" command?
Topic Summary: How to make a KB Command to randomly choose between 0 or 1, then type out the result?
Created On: 03/02/2022 08:42 PM
Status: Post and Reply
Linear : Threading : Single : Branch
Keyword
 03/02/2022 08:42 PM
User is offline View Users Profile Print this message

Author Icon
brainerfan
New Member

Posts: 12
Joined: 10/03/2021

How would I make a KB Command to randomly choose between 0 or 1 (two results), then type out the result?

 

Really need something like this for some work I'm doing, and I'd need this for dozens of values in an Excel sheet. 



 03/03/2022 04:45 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7881
Joined: 03/04/2007

A very quick Advanced Scripting approach might be:

'#Language "WWB-COM"

Option Explicit

Sub Main
Dim ThisSecond As String
ThisSecond = Format(Now, "s") / 60
If ThisSecond > 0.5 Then
SendKeys "1"
Else
SendKeys "0"
End If
End Sub

-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 03/03/2022 09:11 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

I prefer the one-liner:

MsgBox "Random Number " & CStr(Int((2 * Rnd) + 1))

(The "2" can be changed to other dice numbers).

Hth,

-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.

 03/03/2022 09:57 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 7881
Joined: 03/04/2007

A lot more elegant of course, PG. I wasn't aware of the Rnd instruction being availaible here.

-------------------------



No need to buy if all you want to do is try ...

DragonCapture KB Download (Latest)
DragonCapture Homepage

 03/03/2022 10:07 AM
User is offline View Users Profile Print this message

Author Icon
Matt_Chambers
Top-Tier Member

Posts: 582
Joined: 08/09/2018

 03/04/2022 11:43 AM
User is offline View Users Profile Print this message

Author Icon
brainerfan
New Member

Posts: 12
Joined: 10/03/2021

PG LTU, the "MsgBox "Random Number " & CStr(Int((2 * Rnd) + 1))" was the closest one to what I was looking for, though it's not amazing for doing many, many numbers in a row quickly.

Not exactly what I was looking for, but thanks for everyone's help & time regardless.
 03/04/2022 12:32 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Uhm, unclear what you _are_ looking for. The responses are meant as exemplary. You could easily change a MsgBox to SendKeys if that's the problem (RW obviously read the question closer than I did). Did you want multiple numbers in a row? Perhaps this model can get you started. I call the command "some random numbers"

'#Language "WWB-COM"

Option Explicit

Sub Main
Dim x As String
Dim i As Integer
While i < 50
x = x & CStr(Int((2 * Rnd) + 1)) & " "
i = i+1
Wend
Clipboard x
SendKeys "Some Random Numbers ^v"
End Sub


and the output is as such (in under a second):
Some Random Numbers 1 2 2 1 2 2 1 2 2 1 2 1 2 2 2 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1


Hth,

-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.

 03/04/2022 12:38 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

In a blink of an eye, here are 1000 (just by changing 50 to 1000):

Some Random Numbers 1 1 2 2 2 1 2 2 2 2 1 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 1 2 2 1 1 2 2 2 2 2 2 2 1 1 2 2 2 1 1 2 2 2 1 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 2 1 1 2 1 2 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 1 1 2 2 2 1 1 1 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 2 1 2 2 1 1 1 2 2 2 1 1 1 2 1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 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 2 2 2 2 2 2 1 2 1 2 2 1 1 1 1 2 1 2 1 1 1 1 1 1 2 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 1 1 1 2 1 2 2 1 1 1 2 1 1 2 2 1 2 2 1 1 2 1 1 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 1 2 2 2 1 2 1 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 2 2 2 2 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 2 1

-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.

Statistics
32325 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 4 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 477 guests browsing this forum, which makes a total of 481 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.