Jump to content

This is a very edge case thing, but I want to launch either one soundbite or another, randomly, when a batch file is run.

Im using VLC right now.

I tried using this

set /a num=%random% %%1 && if /a = 0 "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\*user*\music\theywillcower.mp3" else "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\*user*\music\notkillmyallies.mp3"

basically trying to chose a random number set between 0 and 1, and if the number is 1, then play theywillcower.mp3 in vlc, which is minimized, if not, then its notkillmyallies.mp3.

 

But nothing happens when I run it.

What's wrong with what I'm doing?

 

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/
Share on other sites

Link to post
Share on other sites

https://ss64.com/nt/syntax-random.html

%RANDOM% generates a random integer from 0 to 32,767 (inclusive)

 

So the chance of getting a 0 or 1 is somewhat small. The link also explains how to limit that number to a range you want.

 

Also

if /a = 0

don't you mean

if /a num = 0

 

Instead of comparing to 0/1, I would change that to something like

if num > 16384, this way you don't have to change the range of the random numbers.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15019036
Share on other sites

Link to post
Share on other sites

8 hours ago, Eigenvektor said:

https://ss64.com/nt/syntax-random.html

%RANDOM% generates a random integer from 0 to 32,767 (inclusive)

 

So the chance of getting a 0 or 1 is somewhat small. The link also explains how to limit that number to a range you want.

 

Also


if /a = 0

don't you mean


if /a num = 0

 

Instead of comparing to 0/1, I would change that to something like

if num > 16384, this way you don't have to change the range of the random numbers.

I did that, switched to /a num=%RANDOM%, and /a num > 16384, bu tit now says num was unexpected at this time. changing the second num to another thing is shows that change in the error message, so it is an issue around the second num

set /a num=%random% && if /a num > 16384 "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\theywillcower.mp3" else "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\notkillmyallies.mp3"

 

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15019530
Share on other sites

Link to post
Share on other sites

4 hours ago, HelpfulTechWizard said:

I did that, switched to /a num=%RANDOM%, and /a num > 16384, bu tit now says num was unexpected at this time. changing the second num to another thing is shows that change in the error message, so it is an issue around the second num

Sorry, that was meant to be pseudo-code. You can't use > in the command line like that, since this is used to redirect output into a file. I think you need to use "GTR" in Windows for "greater than"

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15020014
Share on other sites

Link to post
Share on other sites

1 hour ago, Eigenvektor said:

Sorry, that was meant to be pseudo-code. You can't use > in the command line like that, since this is used to redirect output into a file. I think you need to use "GTR" in Windows for "greater than"

Oh, so something like this?
 

set /a num=%random% && if /a num gtr 16384 "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\theywillcower.mp3" else "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\notkillmyallies.mp3"

 

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15020140
Share on other sites

Link to post
Share on other sites

8 minutes ago, HelpfulTechWizard said:

Oh, so something like this?


set /a num=%random% && if /a num gtr 16384 "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\theywillcower.mp3" else "c:\Program Files\videolan\vlc\vlc.exe" --qt-start-minimized --play-and-exit "C:\Users\Urban\music\notkillmyallies.mp3"

Yeah, like that 🙂

 

I played around a bit in a VM and this is what works for me:

if %random% gtr 16384 (echo "yes") else (echo "no")

You should only have to replace the echo's inside the parentheses with what you want (do keep the parentheses!).

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15020192
Share on other sites

Link to post
Share on other sites

20 minutes ago, Eigenvektor said:

Yeah, like that 🙂

 

I played around a bit in a VM and this is what works for me:


if %random% gtr 16384 (echo "yes") else (echo "no")

You should only have to replace the echo's inside the parentheses with what you want (do keep the parentheses!).

Oh, that saves a command, ill see if that works once I get home

I could use some help with this!

please, pm me if you would like to contribute to my gpu bios database (includes overclocking bios, stock bios, and upgrades to gpus via modding)

Bios database

My beautiful, but not that powerful, main PC:

prior build:

Spoiler

 

 

Link to comment
https://linustechtips.com/topic/1377198-pick-random-in-batch/#findComment-15020245
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×