Solved How to make a word have a 1% chance of being picked?

January 18, 2018 at 20:14:01
Specs: Windows 10
So I am trying to make a batch file with 5 different words.

Example: Yellow, Red, Green, Silver, and Purple.

How can I make it so Silver would have a 1% chance of showing up in my batch?

I want to make it so yellow is the common word to pop up and making the others a set % on how random it would pop up. I want it to be semi random but with having a rare color.


See More: How to make a word have a 1% chance of being picked?

Reply ↓  Report •

✔ Best Answer
January 20, 2018 at 13:01:26
here's a version that allows multiple percents assigned to colors
obviously, it re-iterates until you hit ctrl-c break, unless you put a pause in :xit

@echo off & setlocal
rem these are your percents with colors - don't have to be in order
rem -----------------------
set x=1.silver 12.red 5.purple 20.green 35.blue 27.yellow

:top
set c=
set k=
set /a test=%random%/328
call :aa %x%
goto :top

:aa
set color=%~x1
set /a c+=%~n1
set /a k+=1
if %test% leq %c% goto :xit
shift
if "%1" equ "" goto :bad
goto :aa

:xit
echo %c% %k% %color%
goto :eof

:bad
echo shouldn't be here: %c% %k%
pause
goto :eof



#1
January 18, 2018 at 23:03:53
I'm not sure exactly what you're aiming at, but I'll give you this:

setlocal enabledelayedexpansion
@echo off
:: this next could be any number 0 to 99
set silver=2
rem pauses whenever "silver" number is hit
:aa
:: random is 0 to 32767
set /a q=%random%/327
rem OR %random% %% 100 not sure which is more accurate
echo %q%
if %q% equ %silver% pause
goto :aa


Reply ↓  Report •

#2
January 19, 2018 at 02:13:48
So what I made so far is

My batch file

@echo off

set /a rnd=%random%%%10

for /f "tokens=1,2" %%a in (list.txt) do if %rnd%==%%a echo %%b

pause

and my list is this

1 Yellow_Star
2 Yellow_Star
3 Rare_Star
4 Yellow_Star
5 Uncommon_Star
6 Yellow_Star
7 Common_Star
8 Yellow_Star
9 Silver_Star
10 Yellow_Star


I would rather not have to type yellow star 90 more times to make it the most common, I didn't know if there is a way to use percentage to make it where Silver star is a 1/100 chance etc.


Reply ↓  Report •

#3
January 19, 2018 at 06:50:01
This may save you some clutter.

::======  script starts here  ===============
:: pick silver 1% of the time out of 5
:: stara.bat  2018-01-19 21:14:57.12
@echo off & setLocal enableDELAYedeXpansioN

set/a R=!random!%%100

if !R! equ 0 (
  call :0
) else (
  set/a C=!R!%%4+1 && call :!C!
)
goto :eof

:0
echo silver
goto :eof

:1
echo red
goto :eof

:2
echo purple
goto :eof

:3
echo yellow
goto :eof

:4
echo green
goto :eof

::======  script ends here  =================

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

Related Solutions

#4
January 19, 2018 at 15:12:44
So I am trying what you made and it tries to open but closes the CDM every time? Do I need to add pause to some spots?

Reply ↓  Report •

#5
January 20, 2018 at 13:01:26
✔ Best Answer
here's a version that allows multiple percents assigned to colors
obviously, it re-iterates until you hit ctrl-c break, unless you put a pause in :xit

@echo off & setlocal
rem these are your percents with colors - don't have to be in order
rem -----------------------
set x=1.silver 12.red 5.purple 20.green 35.blue 27.yellow

:top
set c=
set k=
set /a test=%random%/328
call :aa %x%
goto :top

:aa
set color=%~x1
set /a c+=%~n1
set /a k+=1
if %test% leq %c% goto :xit
shift
if "%1" equ "" goto :bad
goto :aa

:xit
echo %c% %k% %color%
goto :eof

:bad
echo shouldn't be here: %c% %k%
pause
goto :eof


Reply ↓  Report •

Ask Question